Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

Error in Obj-C: erminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSo

Hi all,

When I click on my search bar I get this error: terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' . Could somebody please help me troubleshoot&fix this?

Thanks.

Amit Bijlani could you please help me with this? The strange thing is that I do return a cell! This is the error:

reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

The code I use for cellForRowAtIndexPath is:

static NSString *CellIdentifier = @"userCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    PFObject *tempObject = [users objectAtIndex:indexPath.row];

    cell.text= [tempObject objectForKey:@"username"];

    return cell;

Thanks for any help at all!

2 Answers

Adham Gad
Adham Gad
9,899 Points

Check ur implementation of tableView:cellForRowAtIndexPath: Method you should be creating a cell inside that method , assigning it some values and at the end of the method make sure u have returned the cell for example

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];    
cell.textLabel.text = @"some text";
//return cell at the end
return cell;

Adham Gad could you please help me? I do a very similar thing to what you said to do but I retrieve the users from a Parse.com database:

 static NSString *CellIdentifier = @"userCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    PFObject *tempObject = [users objectAtIndex:indexPath.row];

    cell.text= [tempObject objectForKey:@"username"];

    return cell;

Will this still work? And as you can see I do return the cell! Please, please help! Thanks for your help and any help is appreciated!

Adham Gad
Adham Gad
9,899 Points

it should work ! i can't determine what's wrong with the last code u posted i think it's ok except for the cell.text change it to cell.textLabel.text and check the Ribbit app in the teamtreehouse iOS track, you will import data from parse.com and then present it in a tableview most of the time if you are asking if this is applicable then the answer is ofcourse it's ok if there is sth wrong in the last code u posted please try to post more code.