在 table 视图中交替使用两种不同的自定义单元格布局
Alternate two different custom cell layouts in a table view
在我的故事板中,我创建了两个不同的原型单元格,cell1 和 cell2。我希望它们像这样出现在我的 tableView 中:
表格视图
prototype cell1 - indexpath.row[0]
prototype cell2 - indexpath.row[1]
prototype cell1 - indexpath.row[2]
prototype cell2 - indexpath.row[3]
and so on...
我在 cellForRowAtIndexPath:
中尝试了 if
和 switch
语句以及 for
循环,但无法正确使用。然后我在这里和互联网上搜索,但仍然找不到答案。希望有人能给我解释一下吗?
这很容易用 mod 运算符和一个 if 语句来完成,
if (indexPath.row %2 == 0) {
//dequeue cell1 type
// configure the cell
// return cell
}else{
//dequeue cell2 type
// configure the cell
// return cell
}
在我的故事板中,我创建了两个不同的原型单元格,cell1 和 cell2。我希望它们像这样出现在我的 tableView 中:
表格视图
prototype cell1 - indexpath.row[0]
prototype cell2 - indexpath.row[1]
prototype cell1 - indexpath.row[2]
prototype cell2 - indexpath.row[3]
and so on...
我在 cellForRowAtIndexPath:
中尝试了 if
和 switch
语句以及 for
循环,但无法正确使用。然后我在这里和互联网上搜索,但仍然找不到答案。希望有人能给我解释一下吗?
这很容易用 mod 运算符和一个 if 语句来完成,
if (indexPath.row %2 == 0) {
//dequeue cell1 type
// configure the cell
// return cell
}else{
//dequeue cell2 type
// configure the cell
// return cell
}