【发布时间】:2015-02-26 20:45:10
【问题描述】:
我有一个包含多个单元格标识符的自定义单元格。我尝试了以下代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellID;
switch ([indexPath section]) {
case 0:
cellID = @"firstCell";
break;
case 1:
cellID = @"secondCell";
break;
default:
break;
}
customCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
return cell;
}
当我运行应用程序时,它会显示第一个单元格 2 次,即使在情节提要中,有 2 个单元格里面有不同的对象。
【问题讨论】:
标签: ios objective-c uitableview custom-cell