我有一个关于3种不同类型原型单元格的表格视图的简单问题。前两次只发生一次,而第三次发生四次。现在我感到困惑的是如何在我的cellforRowatindexpath中指定哪个单元格原型用于哪一行。所以,我想要的东西就像第0行,使用原型1,第1行,使用原型2,第3,4,5和第6行使用原型3.什么是最好的方法来做到这一点?我是否给每个原型标识符,然后使用dequeueReusableCellWithIdentifier:CellIdentifier? 你能提供一些示例代码吗?TableView与多个原型单元格
编辑:
仍然无法正常工作。这是我目前的代码。 (我只有在一种情况下的switch叙述,因为我只是想测试一下,看看是否是第一行中产生与否的细胞,但目前表视图为空)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
switch(indexPath.row)
{
case 0: {static NSString *CellIdentifier = @"ACell";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"ACell"];
if(cell==nil) {
cell=[[UITableViewCell alloc]
initWithStyle:(UITableViewCellStyleDefault) reuseIdentifier:@"ACell"];
}
return cell;
break;
}
}
}
Acell是我标识符我创建的细胞原型。我
我不undertand你的问题。 –
“我是否给每个原型标识符,然后使用dequeueReusableCellWithIdentifier:CellIdentifier?”是的你是。你几乎已经回答了你自己的问题。 – rdelmar
但我该如何选择哪一个原型适用于哪一行? –