如果UITableView的单元格已准备好重用,则其dequeueReusableCellWithIdentifier方法将很高兴地返回最初在第1节中使用的第0节的单元格!我向您推荐这样的东西,让它们分开:
UITableViewCell *cell;
// Configure the cell.
switch(indexPath.section) {
case 0:
cell = [tableView dequeueReusableCellWithIdentifier:@"Section0Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Section0Cell"] autorelease];
}
// other code
break;
case 1:
cell = [tableView dequeueReusableCellWithIdentifier:@"Section1Cell"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Section1Cell"] autorelease];
// add the overall comment view container to the cell
NLog(@"adding the overallCommentViewContainer");
[cell.contentView addSubview:self.overallCommentViewContainer];
}
NLog(@"creating the row at: Section %d, Row %d", indexPath.section, indexPath.row);
break;
}
return cell;
关键是要为正在使用的每种类型的单元格使用不同的标识符字符串,该字符串不能与表中的其他单元格互换。