Giardino
Giardino

Reputation: 1387

Registered NIB, still getting assertion error when I use dequeueReusableCellWithIdentifier

I have a custom UITableViewCell class that I want to use to create custom table cells. I created the custom table cell's xib as well as its header and implementation files, all called RTRepairOrderTableCell.m/.h/.xib.

My issue is that even though I set the reuse identifier of the table cell to RTRepairOrderTableCell inside of the .xib file and registered the xib inside of my table view controller, I am still getting assertion errors when it tries to dequeue or create a new cell for use.

Inside of my view (table) controller I have the following:

- (void)viewDidLoad
{
    [super viewDidLoad];
    //Load the nib file
    UINib *nib = [UINib nibWithNibName:@"RTRepairOrderTableCell"
                                bundle:nil];
    // Register this Nib, which contains the cell
    [self.tableView registerNib:nib
         forCellReuseIdentifier:@"RTRepairOrderTableCell"];    
}

There are no errors here and it finishes viewDidLoad just fine.

Inside of my cellForRowAtIndexPath I have the following:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{       
    RTRepairOrderTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"RTRepairOrderTableCell" forIndexPath:indexPath];      
    return cell;
}

According to every tutorial I've seen, this should work so long as I have the reuse identifier set properly inside the xib file and I register that xib inside of viewDidLoad in the view controller class that will display the table cells, so I am at a loss as to why I am getting

*** Assertion failure in -[UITableView _dequeueReusableViewOfType:withIdentifier:], /SourceCache/UIKit/UIKit-2935.138/UITableView.m:5413

Upvotes: 1

Views: 2411

Answers (4)

Mattia
Mattia

Reputation: 426

Check if in your .xib there are no UI component outside main layout:

Label is not accepted

In this example, Label is not accepted and cause the exception

Upvotes: 0

iOS_Developer
iOS_Developer

Reputation: 183

I faced this and it was driving me crazy. But it was my fault. I had set identifier @"Abc" in Nib file and I was registering the same nib file with some other identifie @"Xyz". Removed the identifier from nib, left that part blank and it worked like a champ. :)

Upvotes: 1

alexgophermix
alexgophermix

Reputation: 4279

This might be a rare case, but due to some sloppy copy pasta two different UITableViewCell custom classes used in my table had the exact same Identifier specified in the Xib.

Switching one of these cells to have a different Identifier in the Attributes Inspector fixed my Assertion failures.

Upvotes: 0

Giardino
Giardino

Reputation: 1387

Turns out I had a few orphaned UIImage objects inside the nib file but outside of the UITableViewCell area, so it was throwing errors saying that the UITableViewCell needed to be the topmost view.

Upvotes: 10

Related Questions