func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
animations.image = exerciseList[indexPath.row]["animations"] as? [UIImage]
}
我不断收到类型"任何?"错误。我知道这是因为我使用字典将值传递给 TBC。我正在尝试返回包含练习动画的 UI 图像数组。我试图将练习列表本身转换为 [字符串:任意] 然后添加 UI 图像,但我遇到了另一个错误。有人知道我搞砸了吗?
值按原样存储
更新:
if selectedIndexPath.item == 1 {
let squatDictionary = ["name" : "Squat" , "animations" : squatAnimations] as [String : Any]
let jSquatDic = ["name" : "Jump Squat", "animations" : jumpSquatAnimations] as [String : Any]
animationVC.exerciseList = [squatDictionary, jSquatDic]
我的练习列表获取数据声明为:
var exerciseList = [[String : Any]]()
可能是
您遇到误导性错误,问题是您正在设置UIImageView
的属性image
[UIImage]
表示UIImage
数组而不是单个UIImage
对象。如果要使用UIImageView
对多个图像进行动画处理,则需要使用animationImages
使用UIImageView
对图像进行动画处理。
animation.animationImages = exerciseList[indexPath.row]["animations"] as? [UIImage]
animation.animationDuration = 0.5
//If you don't set animationRepeatCount it will animate infinitely
//animation.animationRepeatCount = 5 //Set if you don't want to animate infinitely
//To start animation call startAnimating() on imageView
animation.startAnimating()