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: