Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

iJustinCabral

macrumors member
Original poster
Jul 8, 2012
58
0
Code:
#import "ChecklistsViewController.h"
#import "ChecklistItem.h"

@interface ChecklistsViewController ()

@end

@implementation ChecklistsViewController
{
    NSMutableArray *items;
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    items = [[NSMutableArray alloc] initWithCapacity:20];
    
    ChecklistItem *item;
    
    item = [[ChecklistItem alloc] init];
    item.text = @"Walk the dog";
    item.checked = NO;
    [items addObject:item];
    
    item = [[ChecklistItem alloc] init];
    item.text = @"Brush my teeth";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc] init];
    item.text = @"Learn iOS development";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc] init];
    item.text = @"Soccer practice";
    item.checked = NO;
    [items addObject:item];
    
    item = [[ChecklistItem alloc] init];
    item.text = @"Eat ice cream";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc]init];
    item.text = @"Gout appointment";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc]init];
    item.text = @"Watch Pats game";
    item.checked = NO;
    [items addObject:item];
    
    item = [[ChecklistItem alloc]init];
    item.text = @"Follow Tutorial";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc]init];
    item.text = @"Vote For Ron Paul";
    item.checked = YES;
    [items addObject:item];
    
    item = [[ChecklistItem alloc]init];
    item.text = @"Listen to JRE";
    item.checked = NO;
    [items addObject:item];    
   
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return UIInterfaceOrientationIsPortrait(interfaceOrientation);
}

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

- (void)configureCheckmarkForCell:(UITableViewCell *)cell withChecklistItem:(ChecklistItem *)item
{
    if (item.checked) {
        cell.accessoryType = UITableViewCellAccessoryCheckmark;
    } else {
        cell.accessoryType = UITableViewCellAccessoryNone;
    }
}

- (void)configureTextForCell:(UITableViewCell *)cell withChecklistItem:(ChecklistItem *)item
{
    UILabel *label = (UILabel *)[cell viewWithTag:1000];
    label.text = item.text;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ChecklistItem"];
    
    ChecklistItem *item = [items objectAtIndex:indexPath.row];
    
    [self configureTextForCell:cell withChecklistItem:item];
    [self configureCheckmarkForCell:cell withChecklistItem:item];
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    ChecklistItem *item = [items objectAtIndex:indexPath.row];
    [item toggleChecked];
    
    [self configureCheckmarkForCell:cell withChecklistItem:item];
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end

This is my code, I'm getting this exception when I try to run & build the app:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'


Any idea whats going on?
 
Last edited by a moderator:
This is my code, I'm getting this exception when I try to run & build the app:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'


Any idea whats going on?

It's exactly what the error message says. Your method for tableView:cellForRowAtIndexPath: isn't returning a cell. In fact, it's not returning anything, because it doesn't contain this statement:
Code:
 return cell;


If you're learning from a book or tutorial, which one? (Title, author, edition, or tutorial URL.)

If you're working through an exercise from a book or tutorial, which one? (Chapter, page, exercise number.)


And please read how to use CODE tags.
 
in cellForRowAtIndexPath I am returning cell.


Can you point out which piece of code should say it?

Cause it looks like I have return cell in the right place.


I'm following Ray Wenderlich's Checklist Tutorial (Part 1) from the iOS Apprentice Series.

----------

Never mind I found the problem.

The cell identifier wasn't matched up because I didn't realize it was case sensitive.

Thanks for all the help though.
 
NSLog your Cell pointer right before you return it, there's a high chance it will be null/nil ;)

EDIT: I see you fixed it, sorry, the info I posted is for other people who have the error (even I had it yesterday, after 3 years iOS dev, effing typos..)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.