Okay so Here's my issue. I have a table, a bit like Apple's addressBook.app that uses different cell subclasses to display information in different ways. On this particular app I have 3 different UiTableViewCell subclasses, all with their own nibs.
I can't get the code right :-( if I try and access the instance variable of my cell in the CellForRowPath method it says' (ERROR request for member 'type' in something not a structure or union') Now I assume that the word 'something' is the root of my problem.. The code I am about to paste obviously doesn't setup my cell properly. Here is the code:
There are 3 if statements to get the right cell subclass depending on the section being called:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *PoolFacilityCellIdentifier = @"PoolFacilityCellIdentifier";
static NSString *PoolFacilityAddressCellIdentifier = @"PoolFacilityAddressCellIdentifier";
static NSString *PoolFacilityPoolCellIdentifier = @"PoolFacilityPoolCellIdentifier";
NSUInteger section = indexPath.section;
//Creat a generic container for cell which will be cast during one of the next two statements
id cell;
//Change the identifier depending on cell type. MIGHT NEED TO ADD SOMETHING ELSE FOR POOLS AND PRICES
if (section == KAddressIndex) {
cell = (PoolFacilityAddressCell *)[tableView dequeueReusableCellWithIdentifier:PoolFacilityAddressCellIdentifier];
if (cell == nil) {
//Load the appropriate nib for the type of cell being asked for.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PoolFacilityAddressCell" owner:self options:nil];
for (id object in nib) {
if ([object isMemberOfClass:[PoolFacilityAddressCell class]])
cell = (PoolFacilityAddressCell *) object;
}
}
}
else if (section == KPoolIndex) {
cell = (PoolFacilityPoolCell *)[tableView dequeueReusableCellWithIdentifier:PoolFacilityPoolCellIdentifier];
if (cell == nil) {
//Load the appropriate nib for the type of cell being asked for.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PoolFacilityPoolCell" owner:self options:nil];
for (id object in nib) {
if ([object isMemberOfClass:[PoolFacilityPoolCell class]])
cell = (PoolFacilityPoolCell *) object;
}
}
}
else {
cell = (PoolFacilityCell *)[tableView dequeueReusableCellWithIdentifier:PoolFacilityCellIdentifier];
if (cell == nil) {
//Load the appropriate nib for the type of cell being asked for.
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"PoolFacilityCell" owner:self options:nil];
for (id object in nib) {
if ([object isMemberOfClass:[PoolFacilityCell class]])
cell = (PoolFacilityCell *) object;
}
}
}
Any help would be greatly appreciated!!! I import all the header files for my cell subclasses.
The code that throws my error is this (specifically the cell.type.text = thePool.type) cell.type is an Iboutlet UiLabel:
if (section == KPoolIndex) {
NSMutableArray *thePools = [allSections objectForKey:sectionAsNumber];
if ([thePools count] > 0) {
[cell setPromptMode:NO];
//Set the label and Pool from the Pool Object
Pool *thePool = [thePools objectAtIndex:row];
cell.type.text = thePool.type;
}
}
Thanks,
Dan