Ios “类型”;“有吗?”;没有下标成员(尝试在VC中更新imageview)
我一直收到类型“Any?”错误。我理解这是因为我使用字典将值传递给TBC。我试图返回一个包含练习动画的UI图像数组。我尝试将exerciselist本身转换为[String:Any],然后添加UI图像,但我遇到了另一个错误。有人知道我把事情搞砸了吗 这些值是这样存储的 更新:Ios “类型”;“有吗?”;没有下标成员(尝试在VC中更新imageview),ios,swift,uitableview,Ios,Swift,Uitableview,我一直收到类型“Any?”错误。我理解这是因为我使用字典将值传递给TBC。我试图返回一个包含练习动画的UI图像数组。我尝试将exerciselist本身转换为[String:Any],然后添加UI图像,但我遇到了另一个错误。有人知道我把事情搞砸了吗 这些值是这样存储的 更新: func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { animations.image = ex
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
animations.image = exerciseList[indexPath.row]["animations"] as? [UIImage]
}
我的获取数据的练习表声明为:
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]
可能是您遇到了误导性错误,问题是您正在使用
[UIImage]
设置UIImageView
的image
属性,而不是单个UIImage
对象。如果要使用UIImageView
为多个图像设置动画,则需要使用animationImages
来使用UIImageView
为图像设置动画
var exerciseList = [[String : Any]]()
当您知道您的词典是
[String:[UIImage]]
时,为什么要将其声明为[String:Any]
?更改声明,错误就会消失。否则,为每个步骤使用适当的下拉列表将队列分割,以便swift知道您正在处理的是什么,我们如何声明练习列表
。您好,练习列表是:var exerciseList=[[String:[UIImage]]](我刚刚编辑了它。我试图将字典更改为[String:[UIImage]],但遇到另一个错误“无法将String类型的值转换为预期的字典值类型‘Array’@thelegendary3不您需要设置var exerciseList=[[String:Any]]()”
,然后它就可以编辑您的问题并提供更多信息detail@niravD完成!!!
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()