Ios 多个TableView自定义单元格
因此,我创建了一个带有2个自定义单元格的表视图 我正在尝试将数据输入第三个单元格,但在返回多少单元格时遇到了一个问题&同时也使我的标题数组从第三个单元格开始Ios 多个TableView自定义单元格,ios,swift,tableview,cells,Ios,Swift,Tableview,Cells,因此,我创建了一个带有2个自定义单元格的表视图 我正在尝试将数据输入第三个单元格,但在返回多少单元格时遇到了一个问题&同时也使我的标题数组从第三个单元格开始 func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 3 } func tableView(_ tableView: UITableView, cellForRowAt indexPat
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
}
在最后一种情况下,行不可能等于3。把它改成2 在
func tableView(tableView:UITableView,numberofrowsinssection:Int)中返回3
。所以,行的值仅为[0,1,2]
根据您的代码,您可能会犯错误,将
sliderIndex
设置为1,将instagramIndex
设置为2。它们应该是0和1 我猜sliderIndex=0
和instagramIndex=1
?然后,numberOfRows
等于titleArray.count+2
,在您的else
情况下,只需执行cell3.blogtTitle.text=titleArray[row-3]
或类似操作(可能是+1或-1的错误)。