2017-01-24 11 views
0

私は2つのカスタムセルでテーブルビューを作成しました。複数のTableViewカスタムセル

第3セルにデータを入力しようとしていますが、第3セルからタイトル配列を作成するために何個のセルを返すかに問題があります。&最後のケースでは

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 3 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

    var row = indexPath.row 

    if(row == sliderIndex){ 

     var cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! Row 

     return cell 

    }else if (row == instagramIndex) { 

     var cell2 = tableView.dequeueReusableCell(withIdentifier: "instgramCell", for: indexPath) as! Insta 

     return cell2 

    } else { 

     var cell3 = tableView.dequeueReusableCell(withIdentifier: "blogCell", for: indexPath) as! blogCell 

     if (row == 3) { 

      cell3.blogTitle.text = titleArray[0] 

     }      
     return cell3 
    } 
+0

かもしれません私は 'sliderIndex = 0'と' instagramIndex = 1'を推測していますか? 'numberOfRows'は' titleArray.count + 2'に等しく、 'else'の場合は' cell3.blogTitle.text = titleArray [row-3] 'などとなります(+ 1または-1である。 – Larme

答えて

0

、行は、あなたがfunc tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)に3を返す2.

に3変更にそれを等しくすることは不可能です。だから、列の値は、[0、1、2]

だろうそして、あなたのコードによると、あなたは彼らが0であるべき2にinstagramIndexを1にsliderIndexを設定し、設定ミスを犯すと1

関連する問題