在表视图中替换两个不同的自定义单元格布局

时间:2015-04-01 23:02:09

标签: ios objective-c uitableview cocoa-touch custom-cell

在我的故事板中,我创建了两个不同的原型单元cell1和cell2。我希望它们出现在我的tableView中,如下所示:

的TableView

prototype cell1 - indexpath.row[0]
prototype cell2 - indexpath.row[1]
prototype cell1 - indexpath.row[2]
prototype cell2 - indexpath.row[3]
and so on...

我在if中尝试了switchfor语句以及cellForRowAtIndexPath:循环,但无法做到正确。然后我在这里和互联网上搜索但仍然找不到答案。希望有人可以向我解释一下吗?

1 个答案:

答案 0 :(得分:0)

使用mod运算符和单个if语句

这很简单
if (indexPath.row %2 == 0) {
    //dequeue cell1 type
    // configure the cell
    // return cell

}else{
    //dequeue cell2 type
    // configure the cell
    // return cell
}