3

我正在尝试使用情节提要制作自定义单元格。我已经用基本单元测试了我的程序并且它有效。现在我创建了一个名为 NewsCell 的新类,它包含自定义单元格中的不同标签。我还使单元格成为 NewsCell 的子类。小区标识符是“NewsCell”。

这是 cellForRowAtIndexPath: 方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:@"NewsCell"]; //signal : SIGABRT
    News *info = [self.news objectAtIndex:indexPath.row];
    cell.titreLabel.text = info.titre;
    cell.descriptionLabel.text = info.description;
    return cell;
}

当我运行我的应用程序时,它在第一行以信号信号 SIGABRT 崩溃。我确信我在标签和表格视图单元之间建立了正确的连接。

*** 由于未捕获的异常“NSInternalInconsistencyException”而终止应用程序,原因:“NIB 数据无效。”

4

2 回答 2

13

我有同样的问题。事实证明,我在 Storyboard 文件的 Interface Builder Document 窗格中选中了“Use Autolayout”。这在 iOS 5 上运行时会引发“无效的 NIB”错误,因为自动布局仅在 iOS 6 上受支持。

于 2012-11-08T15:21:14.370 回答
0

您尚未为单元创建实例。尝试为单元创建实例。

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
    NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:@"NewsCell"]; //signal : SIGABRT

     if (cell == nil) {
            cell = [[[NewsCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }
    News *info = [self.news objectAtIndex:indexPath.row];
    cell.titreLabel.text = info.titre;
    cell.descriptionLabel.text = info.description;
    return cell;
}
于 2012-09-25T09:40:28.580 回答