Xcode unable to dequeue a cell with identifier

GoldXApp picture GoldXApp · Sep 30, 2013 · Viewed 74.3k times · Source

my work is about `UITableView. Each time I run my project, this error appears :

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell1 - must register a nib or a class for the identifier or connect a prototype cell in a storyboard

I checked a hundred times my cell identifier in my storyboard and in my code are the same. Code (defaut code from UITableViewController) :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    static NSString *CellIdentifier = @"Cell1";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

Picture of Table View Cell properties : enter image description here

I created and implemented a subclass of UITableViewCell for my cell.

Any idea why this is not working ?

Any way (line of code) to know what is the identifier of a cell ?

Thanks

Edit : Screenshot of my interface builder.

IB

Edit 2 : Text of customCell.h

#import <UIKit/UIKit.h>

@interface customCell : UITableViewCell

@end

New error appears when I run the project :

[<choixActiviteViewController 0x7591ac0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key Cell1.

choixActiviteViewController is a subclass of UITableViewController and is the custom class of Choix Activite View Controller.

Answer

Abdullah Shafique picture Abdullah Shafique · Sep 30, 2013

Instead of:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Try:

 UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if this does not work then, also add:

  if (cell == nil) {
    cell = [[customCell alloc] init];
}