2017-03-18 4 views
-1
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { 

     animations.image = exerciseList[indexPath.row]["animations"] as? [UIImage] 
} 

タイプ「Any?エラー。私はそれがTBCに値を渡すために辞書を使っているからです。私はエクササイズのアニメーションを含むUIイメージの配列を返そうとしています。私はエクササイズ自体を[String:Any]としてキャストしようとしましたが、UI Imageを追加しましたが、別のエラーでヒットしました。誰でも知っているのがうんざりでしたか?タイプ「Any?」 (VCの画像ビューを更新しようとしています)

値は、そのような

更新

として格納されます。

 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] 

私exerciselistデータは次のように宣言されてき:

var exerciseList = [[String : Any]]() 
+0

辞書が '[String:[UIImage]]であることを知っているとき、あなたはなぜ[[String:Any]'として宣言していますか?宣言を変更すると、エラーはなくなります。それ以外の場合は、各ステップごとに適切なダウンキャストでラインを分割してください。 – Paulw11

+0

を処理していることが分かります。「exerciseList」の宣言を表示してください。 –

+0

こんにちは、運動リストは次のとおりです:var exerciseList = [[String:[UIImage]]]()私はそれを編集しました。私は辞書を[String:[UIImage]]に変更しようとしましたが、別のエラーでヒットしました "予想される辞書の値の型に値を変換できません 'Array ' – thelegendary3

答えて

0

すると、あなたが誤解を招くようなエラーを取得していることが、問題がありますあなたはのプロパティをUIImageViewと設定しています。[UIImage]は、UIImageの配列を意味します。単一のUIImageオブジェクトのd。 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() 
関連する問題