0

Essentially I have a table with prototype cells that are loaded dynamically - if criteria is met the UIIView inside a cell will display and play a Lottie animation. The issue is no animation is currently displaying when the tableview cells load:

class NavigationCell: UITableViewCell {
    
    @IBOutlet weak var cellLabel: UILabel!
    @IBOutlet weak var cellAnimation: AnimationView!
    @IBOutlet weak var cellBackground: UIView!

}


    override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {


        let cell = tableView.dequeueReusableCell(withIdentifier: "navCell") as! NavigationCell
        cell.selectionStyle = UITableViewCell.SelectionStyle.none
        cell.textLabel?.font = .systemFont(ofSize: 18)
        cell.textLabel?.textColor = UIColor.black
        let item = structure[indexPath.row]
        cell.cellLabel.text = "\(item.navigation)"
        

        cell.cellAnimation.contentMode = .scaleAspectFit
        cell.cellAnimation.frame = view.bounds
        cell.cellAnimation.loopMode = .loop
        cell.cellAnimation = .init(name: "icon")
        cell.cellAnimation.animationSpeed = 0.5
        cell.cellAnimation.play()
        return cell

        }

Why is the animation not displaying in the dynamic cells?

Update: The animation works inside storyboards but not in code for inside the cell:

Working in Storyboard enter image description here

John
  • 965
  • 8
  • 16
  • Show your code for NavigationCell. – El Tomato May 12 '21 at 04:06
  • The class for navigation cell is in the post - I currently do not have anything more there - the cell design is done in Storyboard – John May 12 '21 at 04:07
  • Any idea why the animation is not presenting in the UIView? – John May 12 '21 at 04:11
  • Oh, I see. I'm sorry about that. – El Tomato May 12 '21 at 04:13
  • No problem, have you run into issues like this? – John May 12 '21 at 04:16
  • What appears and what doesn't? – El Tomato May 12 '21 at 04:17
  • The cells load but the animation inside the cell is not showing at all. – John May 12 '21 at 04:22
  • See this topic. https://stackoverflow.com/questions/57734220/how-to-keep-lottie-animation-running-when-the-view-is-recycled-by-a-tableview – El Tomato May 12 '21 at 04:25
  • @MarkLyson please first check lottie animation working in lottie preview? second you are load it in from local path or sever url both methods are different for both aspect. –  May 12 '21 at 04:37
  • Yes the Lottie itself does work and the path is local inside Xcode project. I noticed the animation does work when referencing the file from storyboards but not the code. I need it work inside the code because I will need to build an if-then for when to present the animation later on. – John May 12 '21 at 04:48
  • sorry for let response `let animation = Animation.named("icon") cell.cellAnimation.animation = animation` your code should be this in cell set it and let me know. –  May 12 '21 at 07:09
  • @RB's That was the issue - thank you very much – John May 13 '21 at 03:01

0 Answers0