繁体   English   中英

带有自定义UITableViewCell的UITableViewController

[英]UITableViewController with custom UITableViewCell

我很好奇为什么在自定义控制器上的tableview单元格时会出现SIGABRT错误。 Cell是在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.

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

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

暂无
暂无

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

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