【问题标题】:Custom UITableViewCell using Storyboard使用 Storyboard 自定义 UITableViewCell
【发布时间】:2012-09-16 18:53:32
【问题描述】:

我正在尝试使用情节提要制作自定义单元格。 我已经用基本单元测试了我的程序并且它有效。 现在我创建了一个名为 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 数据无效。”

【问题讨论】:

    标签: ios5 uitableview storyboard


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 它不起作用,我正在尝试创建一个自定义单元格,而不是基本单元格。
      • 故事板(及其模板单元格)不再需要 cell == nil/create 部分。
      猜你喜欢
      • 2016-02-03
      • 2014-05-18
      • 2011-12-13
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      • 2013-10-11
      相关资源
      最近更新 更多