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 6 でのみサポートされているため、iOS 5 で実行すると「無効な NIB」エラーがスローされます。

于 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 に答える