我有一个包含2个部分的分组表。
第一部分只有1个单元格,它是带有XIB的特定子类。表中的其余单元格显示没有XIB的基本数据。
我遇到的问题是当第一个单元格被重用时,单元格的子类显然仍然是使用XIB的子类,所以当我尝试将数据应用到它时,它不会在他们的位置有任何适当的标签等。
我需要忽略第一个单元格并继续使用第二种类型的单元格,或者更改单元格的类型。
处理这种情况的最佳方法是什么,以及如何完成它?
我试过
if (cell == nil || [cell isKindOfClass:[InspectionMasterTableViewCell class]])
但这似乎没有任何效果。
我的cellForRowAtIndexPath的基本布局是这个
if (indexPath.section == InspectionsMasterSectionData)
{
// CREATE CELL
static NSString *CellWithIdentifier = @"InspectionMasterTableViewCell";
InspectionMasterTableViewCell *cell = (InspectionMasterTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil)
{
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"InspectionMasterTableViewCell" owner:nil options:nil];
cell = [topLevelObjects objectAtIndex:0];
}
return cell;
}
else
{
static NSString *CellWithIdentifier = @"FormTableViewCell";
FormTableViewCell *cell = (FormTableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellWithIdentifier];
if (cell == nil || [cell isKindOfClass:[InspectionMasterTableViewCell class]])
cell = [[FormTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellWithIdentifier];
//CELL DATA
return cell;
}
答案 0 :(得分:3)
通常,每种类型的单元都应该拥有自己的重用标识符。在cellForRowAtIndexPath
中,通过指定正确的重用标识符来询问所需的单元格类型,然后转换为正确的类型。