Exception thrown when trying to reuse cell


#1

I get the following error when running my code:

I’m on pg 303/304 in the 3rd edition and I can’t figure out why my code is wrong. It is below:

[code]- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Set the text on the cell with the description of the item
// that is at the nth index of items, where n = row this cell
// will appear in on the tableview
BNRItem *p = [[[BNRItemStore defaultStore] allItems]
objectAtIndex:[indexPath row]];

//Get the new or recycled cell
HomepwnerItemCell *cell = [tableView dequeueReusableCellWithIdentifier:@"HomepwnerItemCell"];

//Configure the cell wiht the BNRITem
[[cell nameLabel] setText:[p itemName]];
[[cell serialNumberLabel] setText:[p serialNumber]];
[[cell valueLabel] setText:[NSString stringWithFormat:@"$%d", [p valueInDollars]]];

return cell;

}
[/code]

[code]- (void)viewDidLoad
{
[super viewDidLoad];

//Load the NIB file
UINib *nib = [UINib nibWithNibName:@"HomepwnerItemCell" bundle:nil];

//Register this NIB wihich contains the cell
[[self tableView] registerNib:nib forCellReuseIdentifier:@"HomepwnerItemCell"];

}
[/code]

I did an if statement to verify that the nib variable was created and logged to console and it worked. It seems that maybe the registration is wrong? For the life of me I can’t figure this one out.


#2

In your XIB file, look in the object table on the left hand side. Make sure that there is only one object in the “Objects” section and that it is your HomepwnerItemCell.


#3

It looks like everything was an object. I deleted and re-added and everything fell into line. Thanks.


#4

Oddly I had the same issue. Thanks.


#5

Ok, so to my surprise I found an empty tableview object in the xib lurking around. phew.


#6

Same problem. I found an UIImageView object floating around. Should have found that myself, obvious as it was.