我有一个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;
}
编辑为向您显示我的总体布局 – JMD
您是否为InspectionMasterTableViewCell.xib中的单元设置了相同的重用标识“InspectionMasterTableViewCell”? –