Adding custom UITableViewCell crashes the simulator.

Posted by nevva on Stack Overflow See other posts from Stack Overflow or by nevva
Published on 2010-04-23T09:20:11Z Indexed on 2010/04/23 9:23 UTC
Read the original article Hit count: 221

Filed under:
|
|
|
|

Im trying to build my application using a custom UITableViewCell. This is the code in my UIViewController that adds the viewCell to the table:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{   
    NSLog(@"------- Tableview --------");

    static NSString *MyIdentifier = @"MyIdentifier";
    MyIdentifier = @"aCellIdentifier";

    MyTableCell *cell = (MyTableCell *)[tableView dequeueReusableCellWithIdentifier:MyIdentifier];
    if(cell == nil) {
        NSArray *[[NSBundle mainBundle] loadNibNamed:@"tblCellView" owner:self options:nil];
        cell = tblCell;
    }

    [cell setLabelText:[NSString stringWithFormat:@"indexpath.row: %d", indexPath.row]];

    //cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
    return cell;
}

if i uncomment the line above "return cell" it returns a regular UITableViewCell without any errors, but as soon as i try to implement my custom cell it crashes with this error:

------- Tableview -------- 2010-04-23 11:17:33.163 SogetGolf[26935:40b] * Assertion failure in -[UITableView _createPreparedCellForGlobalRow:withIndexPath:], /SourceCache/UIKit_Sim/UIKit-984.38/UITableView.m:4709 2010-04-23 11:17:33.164 SogetGolf[26935:40b] * Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'UITableView dataSource must return a cell from tableView:cellForRowAtIndexPath:' 2010-04-23 11:17:33.165 SogetGolf[26935:40b] Stack: (

...

I have configured the .xib file as one should with the proper outlets. And the identifier of the UITableViewCell corresponds with name im trying to load from NSBundle

© Stack Overflow or respective owner

Related posts about iphone

Related posts about objective-c