2016-10-11 7 views
0

ここでは私のスウィフト2のコードです:メンバーの添字」へのあいまいな参照

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell: UITableViewCell! 
    cell = tableView.dequeueReusableCellwithIdentifier: forWithIdentifier("idCellChannel", forIndexPath: indexPath as IndexPath) 

    let channelTitleLabel = cell.viewWithTag(10) as! UILabel 
    let thumbnailImageView = cell.viewWithTag(12) as! UIImageView 

    let channelDetails = channelsDataArray[indexPath.row] 
    channelTitleLabel.text = channelDetails["title"] as? String 

    // Error Ambiguous reference to member 'subscript' 
    thumbnailImageView.image = UIImage(data: NSData(contentsOfURL: NSURL(string: (channelDetails["thumbnail"] as? String)!)!)!) 

    return cell 
} 

私にあなたがchannelsDataArray[indexPath.row]がいるのでDictionaryで、コンパイラに指示する必要がありスウィフト3.

+0

let 'channelDetails = channelsDataArray [indexPath.row]を次のようにしよう! Dictionary

+0

あなたの質問を 'channelsDataArray'の宣言で更新してください。 – rmaddy

+0

また、どのラインが実際にエラーを出しているかを明確にします。あなたのエラーのコメントは、その行の前または後ろの行に適用されましたか? – rmaddy

答えて

0

のためのソリューションを教えてくださいあなたはsubscriptとすることができます。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let channelsDataArray = [[String: AnyObject]]()//This is your array of dictionaries 
    let cell = tableView.dequeueReusableCell(withIdentifier: "idCellChannel", for: indexPath) as! UITableViewCell 

    let channelTitleLabel = cell.viewWithTag(10) as! UILabel 
    let thumbnailImageView = cell.viewWithTag(12) as! UIImageView 
    let channelDetails = channelsDataArray[indexPath.row] 
    channelTitleLabel.text = channelDetails["title"] as? String 
    thumbnailImageView.image = UIImage(data: NSData(contentsOf: NSURL(string: (channelDetails["thumbnail"] as? String)!)! as URL)! as Data) 

    return cell 
} 

そしてまた、あなたのアプリがクラッシュするだろう場所のほとんどでアンラップ力なのでnilをチェック:コードの下に試してみてください。 guard letまたはif letを使用します。

+0

'channelsDataArray'の宣言を変更して、その配列の内容を指定する方が良いのではないでしょうか。次に、それにアクセスするすべてのコード行にキャストする必要はありません。 – rmaddy

+0

はい、それは本当に、私のコードを更新し、Swift3 – Santosh

関連する問題