1

I keep getting this error, I have set up a custom cell I am trying to display I have connected the datasource and delegates in IB, but I keep getting this error, below is my code... its madness as I have already done this in another project and it works sweet.. and I havent changed anything other than variable names.

2011-05-06 10:40:17.004 instaCode1.3[1500:207] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:'

everything has been @synthesized etc...

#pragma mark -
#pragma mark Table view data source
// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}


// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}

//This method adds headings to my sections
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
    NSString *title = nil;
    // Return a title or nil as appropriate for the section.
    switch (section) {
        case REG_SECTION:
            title = @"Enter Registration";
            break;
        default:
            break;
    }
    return title;;
}

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    if (indexPath.section == 0) {

        return cellRegistration;            

    }
    return 0;
}
tinhead
  • 385
  • 2
  • 10
  • 29

3 Answers3

4

The cellForRowAtIndexPath: function returns a UITableViewCell object and thus 0 is not a valid return option. You must return a cell.

Alexander
  • 8,117
  • 1
  • 35
  • 46
1

If you have a custom cell then you must check the registration of the CELL. This should not be nil under any circumstances.

If its nil then you can use ALLOC, INIT to get the cell registration and return the same.

Kunjal
  • 308
  • 1
  • 4
  • 11
0

I think you're asking for trouble with "return 0" from cellforRowAtIndexPath. I'd put a breakpoint at that line and see if that's where it's breaking, and if so, why is the section != 0?

Is REG_SECTION == 0 (are you sure?)

Edit: What does this give you in the log?

    if (indexPath.section == 0) {
        NSLog(@" cellRegistration is %@",cellRegistration);
        return cellRegistration;            
    }
Rayfleck
  • 12,116
  • 8
  • 48
  • 74
  • Yea, but without that return 0 it throws 'control reaches end of non void function'... Man just getting abit lost in this as I have done this very same thing before.. – tinhead May 05 '11 at 23:20
  • For that case you want to return nil, not 0. – Rayfleck May 05 '11 at 23:23
  • oh, thanks for that. Unfortunatly its still giving me the same error... I think I might just recreate the files and see if that resolves the problem.. Just so weird... – tinhead May 05 '11 at 23:31
  • Have you tried all the usual things like Clean all targets, and reset content for the simulator, close/re-open the project, etc? – Rayfleck May 05 '11 at 23:33
  • Nope Will try those things now. what dose cleaning the targets do? Sorry still fairly new to xcode. – tinhead May 05 '11 at 23:35
  • Basically it deletes all of the object code (compiler output) so you start over. It's a good habit to get into to do that every hour or so. And for the Sim, go to iOS Simulator menu, click "Reset contents and settings..." which uninstalls the app to force a re-install. – Rayfleck May 05 '11 at 23:42
  • Cool thanks, will give those things ago. If I'm still getting the same error after I think I'm just going to try deleting the files and starting fresh. Will let you know how I go. – tinhead May 05 '11 at 23:53
  • 1
    just initialize `cellRegistration`. Because it is nil. Or replace the whole thing with something that makes sense. – Matthias Bauch May 06 '11 at 01:45
  • cellRegistration gets assigned to the custom UItableViewCell that I have made in Interface Builder. – tinhead May 06 '11 at 01:50
  • No I'm pretty sure my code is sound.. I have been over it about 30 times re done the files several times cleared targets the LOT!!! its something to do with the way I have subclassed viewcontroller.. something is wrong there im just not sure what. – tinhead May 06 '11 at 02:48
  • @fluchtpunkt why dosn't it make sense? how do I initialize it? – tinhead May 06 '11 at 03:25