2016-09-15 22 views
0

テーブルに2つの異なるセルを表示する必要があります。プロトタイプをテーブルに設定して試しました。まだそれはPrototype table cells must have reuse identifiers警告を表示しています。UITableViewで2つのカスタマイズされたセルを表示する方法

この警告を解決するには、誰かを案内してください。ストーリーボードで UITableview with more than One Custom Cells with Swift

+0

。 –

+0

@SaurabhPrajapatiそうですね。しかし、私はプロトタイプを使って間違いを知りたいと思っています。 – Dee

答えて

1

はあなたがこの

のように特定のセルのための特定の識別子を使用する必要が cellForRowAtIndexPathenter image description here

そして、下の画像のような細胞のための識別子を定義する必要があります。

は、このリンクをたどっ

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    if indexPath.row == 0 { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Identifier1") 
     //set the data here 
     return cell 
    } 
    else if indexPath.row == 1 { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "Identifier2") 
     //set the data here 
     return cell 
    } 
} 
+0

私はそれをしましたが、私はセルをロードすることができません。私はどこに間違っているのかわからない – Dee

+0

@Deeブレークポイントを追加し、セルのオブジェクトを取得しているかどうかをチェックします。 – Rajat

1

プロトタイプセルの両方にReuse Identifierを設定する必要があります。次に、cellForItemAtIndexPathメソッドでは、指定されたindexPathに基づいて対応するReuse Identifierを使用してセルをデキューする必要があります。代わりに、2つの異なるビューで一つのセルを使用することができる2個の異なる細胞の

Reuse Identifier

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableView { 

    switch indexPath.section { 
    case 0: 
     return tableView.dequeueReusableCellWithIdentifier("CustomCell1", forIndexPath: indexPath) 
    case 1: 
     return tableView.dequeueReusableCellWithIdentifier("CustomCell2", forIndexPath: indexPath) 
    break: 
     return UITableViewCell() 
    } 
} 
関連する問題