BnJ BnJ - 3 months ago 27
Objective-C Question

NSInternalInconsistencyException after UITableView reloadData

I have a problem when I add an object in the

NSMutableArray
linked to my
UITableView
after a
reloadData
...

I got this error :

*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-3318.16.14/UITableView.m:7344
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'


Add :

self.relatedArtists = [[NSMutableArray alloc]init];

Artist* test = [[Artist alloc]init];
test.name = @"Test 1";
[self.relatedArtists addObject:test];

Artist* test2 = [[Artist alloc]init];
test2.name = @"Test 2";
[self.relatedArtists addObject:test2];

[self.artists reloadData];


numberOfRowsInSection
&
cellForRowAtIndexPath
:


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.relatedArtists count];
}

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

UITableViewCell *cell = [self.artists dequeueReusableCellWithIdentifier:@"ARTIST_CELL_ID"];

Artist *artist = self.relatedArtists[indexPath.row];
cell.textLabel.text = artist.name;

return cell;
}


I think I missed something in the
Main.storyboard
file, but I don't see what...

Answer

I think you missed setting identifier of your tableView cell in storyboard to ARTIST_CELL_ID.