Why does Custom UITableViewCell *sometimes* cause an NSInvalidArgumentException?
Posted
by Wayne Hartman
on Stack Overflow
See other posts from Stack Overflow
or by Wayne Hartman
Published on 2010-06-11T03:19:53Z
Indexed on
2010/06/11
3:22 UTC
Read the original article
Hit count: 223
iphone
|objective-c
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;
}
© Stack Overflow or respective owner