繁体   English   中英

TableView NSInternalInconsistencyException

[英]TableView NSInternalInconsistencyException

更新:似乎我设法确定了该单元格,因此原来的问题已解决。 但是现在,在删除了相同代码的情况下,出现以下错误:

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) 

//更新结束

我正在尝试查询数据库,然后第一次在表中列出结果。

当我将numberOfRowsInSection从0更改为[matchingData count]时,应用程序崩溃,并显示NSInternalInconsistencyExceptionException错误。 matchingData是一个数组,其中包含核心数据的结果。 我只是不知道为什么[matchingData count]不起作用。

这是我的代码:

- (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;
}

这是例外:

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) 

非常感谢你。

您必须为Nib / Storyboard中的原型单元分配正确的单元标识符。

错误很明显:“无法使标识符为Cell的单元出队-必须为该单元注册一个nib或一个类

代替:

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

请尝试以下操作:

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

测试单元格是否为空非常重要,总是发生在本节中配置的第一个单元格上

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

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

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

祝你今天愉快

暂无
暂无

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

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