简体   繁体   中英

TableView NSInternalInconsistencyException

Update: It seems like I managed to identify the cell, so the original problem is solved. But now, with the same code snipped, I get the following error:

2012-10-31 15:21:41.857 Laktase[22658:11603] -[NSManagedObject isEqualToString:]: unrecognized selector sent to instance 0x74a5a30
2012-10-31 15:21:41.858 Laktase[22658:11603] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSManagedObject isEqualToString:]: unrecognized selector sent to instance 0x74a5a30'
*** First throw call stack:
(0x1f9f012 0x13dce7e 0x202a4bd 0x1f8ebbc 0x1f8e94e 0x1714af 0x171674 0x4430 0xd2f4b 0xd301f 0xbb80b 0xcc19b 0x6892d 0x13f06b0 0x259bfc0 0x259033c 0x259beaf 0x1078cd 0x501a6 0x4ecbf 0x4ebd9 0x4de34 0x4dc6e 0x4ea29 0x51922 0xfbfec 0x48bc4 0x48dbf 0x48f55 0x51f67 0x15fcc 0x16fab 0x28315 0x2924b 0x1acf8 0x1efadf9 0x1efaad0 0x1f14bf5 0x1f14962 0x1f45bb6 0x1f44f44 0x1f44e1b 0x167da 0x1865c 0x268d 0x25b5 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

// End of Update

I'm trying to query a database and then list the results in a table for the first time.

When I change the numberOfRowsInSection from 0 to [matchingData count], the app crashes with a NSInternalInconsistencyException error. matchingData is an array with the results from core data. I just can't figure out why [matchingData count] doesn't work.

Here's my code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tablette" inManagedObjectContext:context];
    NSFetchRequest *request = [NSFetchRequest new];
    [request setEntity:entity];
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dosis >= 0"]; // @"ANY Tablette.dosis like '1'"];
    [request setPredicate:predicate];
    NSError *error;
    NSArray *matchingData = [context executeFetchRequest:request error:&error];
    return [matchingData count];
}

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

// Configure the cell...


NSEntityDescription *entity = [NSEntityDescription entityForName:@"Tablette" inManagedObjectContext:context];
NSFetchRequest *request = [NSFetchRequest new];
[request setEntity:entity];
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"dosis >= 1"];
[request setPredicate:predicate];
NSError *error;
NSArray *matchingData = [context executeFetchRequest:request error:&error];

cell.textLabel.text = [matchingData objectAtIndex:indexPath.row];

return cell;
}

Here is the exception:

2012-10-31 12:10:38.995 Laktase[21797:11603] *** Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
2012-10-31 12:10:38.996 Laktase[21797:11603] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
*** First throw call stack:
(0x1f9f012 0x13dce7e 0x1f9ee78 0xb66f35 0xc9d14 0x4078 0xd2f4b 0xd301f 0xbb80b 0xcc19b 0x6892d 0x13f06b0 0x259bfc0 0x259033c 0x259beaf 0x1078cd 0x501a6 0x4ecbf 0x4ebd9 0x4de34 0x4dc6e 0x4ea29 0x51922 0xfbfec 0x48bc4 0x48dbf 0x48f55 0x51f67 0x15fcc 0x16fab 0x28315 0x2924b 0x1acf8 0x1efadf9 0x1efaad0 0x1f14bf5 0x1f14962 0x1f45bb6 0x1f44f44 0x1f44e1b 0x167da 0x1865c 0x249d 0x23c5 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb) 

Thank you very much.

You must assign the correct Cell identifier to your prototype cell in the Nib/Storyboard.

The error is clear: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for

Instead of:

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

Try the following:

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

Very important to test if cell is null, always happens to the first cell configured in section

if (cell == nil)
{ //alloc the cell explicitily

    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:kCellID];
    .....
}

// Configure the cell.
[self configureCell:cell atIndexPath:indexPath];

Have a nice day

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM