场景 = 我有一个 tableView 将由单个数据数组加载(来自互联网,所以我不能“硬编码”这个)。将有两个不同的 tableView 单元格,我想一个接一个地在这两种类型之间交替。 “CELL A”右侧有文字,左侧有图片,“CELL B”左侧有文字,右侧有图片。下面我有点说明了所需的结果(不意味着是“代码”,只是为了说明 tableView 中从一个单元格到另一个单元格的交替)。
tableView =
[0]indexPath.row = "CELL A"
[1]indexPath.row = "CELL B"
[2]indexPath.row = "CELL A"
[3]indexPath.row = "CELL B"
[4]indexPath.row = "CELL A"
[5]indexPath.row = "CELL B"
问题 = 我不确定如何为两种不同类型的单元格 dequeueForReuseIdentifier。
请求=任何人都可以帮助我使用此代码,或者至少为我指出正确的方向,或者这甚至可能吗?
多谢你们!
最佳答案
这其实很简单。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row % 2 == 0) {
// setup and return table cell type A
} else {
// setup and return table cell type B
}
}
关于ios - 在两种不同类型的 UITableViewCells 之间交替,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24271306/