UITableViewController与自定义的UITableViewCell

我很好奇,为什么当我在控制器上定制一个tableview单元格时,会出现SIGABRT错误。 Cell是在UITableViewCell类中创build的,所有链接都可以看到。 UITableViewController不是rootController,而是一个closures另一个UITableViewController的控制器。 所以RootView – > TableViewCont – >这个TableViewCont。

错误在cellForRowAtIndexPath函数中:

 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"CellTest"; CellTest *cell = (CellTest *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CellTest" owner:self options:nil];//**error is thrown here**// for(id currentObject in topLevelObjects){ if([currentObject isKindOfClass:[UITableViewCell class]]){ cell = (CellTest *) currentObject; break; } } } // Configure the cell... cell.cellTitle.text = @"Test"; cell.cellDescription.text = @"little detail"; return cell; } 

这是gdb日志中的错误:

 Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<DemoViews 0x6b16ce0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key cellDescription. 

我有同样的问题,不明白为什么我得到SIGABRT。 但是我解决了这个问题:

  1. 首先将你的单元格的布局放入一个单独的xib中。 不要问为什么,如果在xib中有其他的东西,就不行。
  2. 现在您可以按照Apple的配方创build自定义单元格 。