Tuesday, 20 August 2013

Change a re-used cell's type?

Change a re-used cell's type?

I have a grouped table of 2 sections.
The first section is only 1 cell and it is a specific subclass with XIB.
The rest of the cells in the table display basic data without XIB.
The issue I am having is when the very first cell goes to be re-used, the
cell's subclass is obviously still that of the one that uses the XIB, so
when I attempt to apply data to it, it doesn't have any of the proper
labels etc in their locations.
I need to either ignore the first cell and keep using the second type of
cell, or change the cell's type.
What is the best way to handle this situation, and how do you accomplish it?
ive tried
if (cell == nil || [cell isKindOfClass:[InspectionMasterTableViewCell
class]]) but this doesn't seem to have any effect.
The basic layout of my cellForRowAtIndexPath is this
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;
}

No comments:

Post a Comment