2017-01-24 106 views
0

所以我创建了2个自定义单元格的表格视图。多个TableView自定义单元格

我想输入数据到第三个单元格,但即时通讯有一个问题,当返回多少单元格&也使我的标题数组从我的第三个单元格开始。

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

在最后一种情况下,一行是不可能等于3。将其更改为2

您在func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)返回3。所以行的值仅是[0,1,2]

并根据您的代码,您可能认为设置sliderIndex为1,并设置instagramIndex为2个错误,他们应该是0和1

相关问题