'unable to dequeue a cell with identifier

My application crashes when I attempt to dequeus a cell in a table view.

This particular app is contructed with a main storyboard with xib files supporting additional details.

The bulk of the code is in objective C

I have contsructed an xib containing some top level infomation and a table view with the details

I then constructed a table view cell containing the detailed information.

When I configured the table view cell, I gave it a reuseidentifer of @"AmtCell".

The code in my controller that attempts to write into the table view cell is:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {


static NSString *CellIdentifier = @"AmtCell";


AmortizationTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier

forIndexPath:indexPath] ;

...... some details ...

}

It crashes when I attempt to dequeue a cell.

'unable to dequeue a cell with identifier AmtCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

The xib file AmortizationTableViewCell.xib is in my project and there are no errors when it is built. Is it being properly loaded in my app?

Accepted Answer

Your description is not entirely clear (is the UITableView in the storyboard or is it in a separate XIB?), but the key point is that you say you have a specific XIB file for the cell (AmortizationTableViewCell.xib). That means you don't have a prototype of that cell type in the table view itself, right? (By "in the table view", I mean shown in the table view under the heading "Prototype cells".)


If all that's true, then you must register the name of the XIB file (really, the name of the generated NIB file) with the table view, using the "registerNib:forCellReuseIdentifier:" method of UITableView.

I was eventually able to make this work.


In the interface I defined a UINib as follows

UINib *cellNib;

In the loadview method I registered the nib as follows

cellNib = [UINib nibWithNibName:@"AmortizationTableViewCell" bundle:nil];

[amortizationTableView registerNib:cellNib forCellReuseIdentifier:@"AmtCell"];

and I was able to make it work.

This app is a recreation of an app that I developed before there were storyboards and swift in Xcode. At that time it was suffient to define a table view cell in an xib file configuring in the reuseidentifer and then put the resuseidentifer in the table view code without having to register the xib in the table view code.

This apparently got broken in later versions of Xcode when storyboards came into use.

Thanks again for your suggestion.

'unable to dequeue a cell with identifier
 
 
Q