2017-11-04 1 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에서 직면 한 문제라고 생각합니다.

// 배열이입니다 myPosts의 사전 가정 [문자열 : 문자열]

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 
} 

감사

을 입력 배열의 사전을 가져 오는 동안, 다음과 같은 코드를 포함