JND JND - 1 year ago 113
iOS Question

Could not load NIB in bundle ! Customs Cell in TableView

I have a problem with my

. I want have 6 different cell in the

So, in the
, i have this:

[_tableView registerNib:[UINib nibWithNibName:@"KBCategoriePriceTableViewCell" bundle:nil]

For other cells, it's the same code and, in the

- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
NSString* nameCell = [array objectAtIndex:indexPath.row];

if([nameCell isEqualToString:CELL_VIEW_CATEGORY_PRICE]){
KBCategoriePriceTableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"KBCategoriePriceTableViewCell"];
[cell setBackgroundColor:[[receive category] colorBackground]];
[cell.buttonCategorie setTitle:@"" forState:UIControlStateNormal];
[cell.buttonCategorie setEnabled:NO];
[cell.buttonCategorie setImage:[UIImage imageNamed:[[receive category] imageName]]forState:UIControlStateNormal];
[cell.buttonDevise setTitle:[[receive devise] symbole] forState:UIControlStateNormal];
[cell.buttonCategorie setEnabled:NO];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
return cell;

But when i launch my app, it's crash ! With this error message :

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle </Users/jean-nicolasdefosse/Library/Application Support/iPhone Simulator/7.1/Applications/20031DF6-D297-44D0-9D67-4AD3439D85F7/KillTheBill.app> (loaded)' with name 'KBCategoriePriceTableViewCell''

I don't understand why it doesn't work.

I remove reference and add the files in the project, i check the target and the custom cell
have as identifier in "xib":

Please help me !

Answer Source

Error message is saying that you do not have a file named KBCategoriePriceTableViewCell.nib in your project.

Also you should always return a cell in the tableView:cellForRowAtIndexPath:.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download