带有自定义UITableViewCell的UITableViewController

时间:2012-03-02 20:33:41

标签: ios uitableview customization

我很好奇为什么在自定义控制器上的tableview单元格时会出现SIGABRT错误。单元格是在UITableViewCell类中创建的,所有链接都是我能看到的。 UITableViewController不是rootController,而是关闭另一个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.

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,并且不明白为什么我会收到SIGABRT。但是我解决了这个问题:

  1. 首先将单元格的布局放入单独的xib中。不要问为什么,如果xib中还有其他东西,它就不起作用。
  2. 现在您可以关注recipe of Apple for creating custom cells
相关问题