JND JND - 1 month ago 8
iOS Question

Could not load NIB in bundle ! Customs Cell in TableView

I have a problem with my

tableView
. I want have 6 different cell in the
tableView
.

So, in the
viewDidLoad
, i have this:

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


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

- (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
KBCategoriePriceTableViewCell
have as identifier in "xib":
KBCategoriePriceTableViewCell
.

Please help me !

Answer

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:.

Comments