简体   繁体   English

TableView NSInternalInconsistencyException

[英]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. 当我将numberOfRowsInSection从0更改为[matchingData count]时,应用程序崩溃,并显示NSInternalInconsistencyExceptionException错误。 matchingData is an array with the results from core data. matchingData是一个数组,其中包含核心数据的结果。 I just can't figure out why [matchingData count] doesn't work. 我只是不知道为什么[matchingData count]不起作用。

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. 您必须为Nib / Storyboard中的原型单元分配正确的单元标识符。

The error is clear: 'unable to dequeue a cell with identifier Cell - must register a nib or a class for 错误很明显:“无法使标识符为Cell的单元出队-必须为该单元注册一个nib或一个类

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 祝你今天愉快

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NSInternalInconsistencyException 更新 Tableview - NSInternalInconsistencyException updating Tableview NSInternalInconsistencyExceptionException tableView行删除 - NSInternalInconsistencyException tableView row deletion TableView应用程序因'NSInternalInconsistencyException'而终止 - TableView app terminated due to 'NSInternalInconsistencyException' NSInternalInconsistencyExceptionException错误删除表视图单元格 - NSInternalInconsistencyException error removing tableview cell NSInternalInconsistencyException:带有部分的tableView中的无效更新 - NSInternalInconsistencyException: Invalid update in tableView with sections TableView:捕获“NSInternalInconsistencyException”后如何继续? - TableView: How to proceed after catching 'NSInternalInconsistencyException'? 尝试在tableView中插入行时出现NSInternalInconsistencyException - NSInternalInconsistencyException when trying to insert row in tableView 在情节提要中自定义表视图单元时出现NSInternalInconsistencyException - NSInternalInconsistencyException when customize tableview cell in storyboard Tableview更新“ NSInternalInconsistencyException”,原因:“无效的更新:无效的行数? - Tableview update 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows? TableView:由于未捕获的异常“NSInternalInconsistencyException”错误而终止应用程序 - TableView : Terminating app due to uncaught exception 'NSInternalInconsistencyException' Error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM