【问题标题】:NSInternalInconsistencyException when customize tableview cell in storyboard在情节提要中自定义表格视图单元格时出现 NSInternalInconsistencyException
【发布时间】:2016-08-05 08:24:18
【问题描述】:

我想使用故事板创建自定义UITableViewCell,当我运行我的程序时,它崩溃了,这是日志:

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“UITableView (;animations = { position=;};layer = ; contentOffset: {0, 0}; contentSize: {375, 304.23076923076923}>)未能从其dataSource()'中获取单元格

我只是使用它的标识符来获取我的 tableviewcell:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ThemeCell *cell = [tableView dequeueReusableCellWithIdentifier:@"themecell"];

    return cell;
}

以下是我的故事板中的一些限制:

constraints

【问题讨论】:

标签: ios objective-c uitableview


【解决方案1】:

1) 确保您使用的是正确的 tableviewcell 标识符。 2)然后,这样做:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ThemeCell *cell = (ThemeCell *)[tableView dequeueReusableCellWithIdentifier:@"themecell"];
    return cell;
}

【讨论】:

    【解决方案2】:

    如果您使用Storyboard,请确保在此选项卡中设置UITableViewCell 标识符

    【讨论】:

    • 谢谢,我只是弄错了,我把标识符当作恢复标识符。