UITableViewController with custom UITableViewCell

前提是你 提交于 2019-12-25 03:23:01

问题


I was curious why I would be getting a SIGABRT error when I am customizing a tableview cell on a controller. The Cell is created in a UITableViewCell class everything is linked that I can see. The UITableViewController is not the rootController but a controller off the root off another UITableViewController. so RootView -> TableViewCont -> This TableViewCont.

The error is in the cellForRowAtIndexPath function:

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

This is the error in the gdb log:

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:


I had the same issue and did not understand why I am getting SIGABRT. However I resolved the problem:

  1. First place the layout of your cell into a separate xib. Don't ask why, it just doesn't work if there're other things in the xib.
  2. Now you can follow the recipe of Apple for creating custom cells.


来源:https://stackoverflow.com/questions/9539960/uitableviewcontroller-with-custom-uitableviewcell

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!