2017-11-04 29 views
-1

辞書の配列からUITableVIewを読み込もうとしています。これは私のtableView/cellForRowAtメソッドです。 myPostsは辞書が内部にある配列です。 [indexPath.row]を使用すると、型が「Any」に変更され、dictでキャストできません。 私の質問は、indexPathを使用して辞書キーの値にアクセスする方法ですか?辞書の配列からUITableViewを読み込むSwift

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! CustomCell 

    let activePosts = myPosts[indexPath.row] 
    print(activePosts) 
    cell.customCellUsername.text = myUser 
    cell.customCellPost.text = 
    cell.customCellImage.image = 
    cell.customCellUserImage.image = 
    return cell 
} 

答えて

0

私はタイプキャストがcellForRowAtIndexPathに直面している問題だと思います。アレイから辞書を取得中に、次のコードを含む:

if let postDictionary = myPosts[indexPath.row] as? [String:String] { 
    print(postDictionary) //Will print the dictionary in the array for 
         // index as equal to indexpath.row 
} 

おかげ

を入力:myPosts配列内の辞書を仮定

//は[文字列]であります

関連する問題