Why does Custom UITableViewCell *sometimes* cause an NSInvalidArgumentException?
- by Wayne Hartman
I have created a custom UITableViewCell, but when I dequeue the cell, sometimes it throws an NSInvalidArgumentException:
[UITableViewCell nameLabel]:
unrecognized selector sent to instance
0x3b4e7f0
Terminating app due to uncaught
exception
'NSInvalidArgumentException', reason:
'* -[UITableViewCell nameLabel]:
unrecognized selector sent to instance
0x3b4e7f0'
Now, my custom UITableViewCell does have an attribute nameLabel, so I am confused why it is throwing this error. Below is the code I use to dequeue the cell:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
CTMenuItemVO* key = [[[self retrieveCartItems] allKeys] objectAtIndex:row];
NSNumber* quantity = [[self retrieveCartItems] objectForKey:key];
static NSString* SectionsTableIdentifier = @"SectionsTableIdentifier2";
OrderItemCell* cell = (OrderItemCell*)[tableView dequeueReusableCellWithIdentifier:
SectionsTableIdentifier];
if (cell == nil) {
NSArray* topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"OrderItemCell"
owner:nil
options:nil];
for(id currentObject in topLevelObjects)
{
if ([currentObject isKindOfClass:[UITableViewCell class]])
{
cell = (OrderItemCell*) currentObject;
break;
}
}
}
cell.nameLabel.text = key.Name;
cell.qtyLabel.text = [quantity stringValue];
return cell;
}