0

iOS アプリケーションで動的テーブルを作成しようとしていますが、悪名高いメッセージが引き続き表示されます。

識別子 CEMBurialCell を持つセルをデキューできません - 識別子の nib またはクラスを登録する必要があります".

以下は、動作していない私のコードです。

以下は、メインコントローラーの一部のデータです。

#import "CEMBurialCell.h"    // The custom cell I want to use in the tableView

@interface CEMMainViewController () <UITextFieldDelegate, UITableViewDataSource, UITableViewDelegate>
{
    UITableView *deathstoday;
}

これはviewWillAppear:メソッド内のコードです。

deathstoday = [[UITableView alloc] initWithFrame:CGRectMake(1, 370, 300, 50)];
deathstoday.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
deathstoday.delegate = self;
deathstoday.dataSource = self;
deathstoday.scrollEnabled = YES;    
[self.view addSubview:deathstoday];    
[self fetchfeed];   // This populates the array for the tableview

これはviewDidLoadメソッド内のコードです。

UINib *nib = [UINib nibWithNibName:@"CEMBurialCell" bundle:nil];    
[deathstoday registerNib:nib forCellReuseIdentifier:@"CEMBurialCell"];

ここでエラーが発生します:

識別子 CEMBurialCell を持つセルをデキューできません - 識別子の nib またはクラスを登録するか、ストーリーボードのプロトタイプ セルを接続する必要があります。

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

メソッドでを初期化したCEMBurialCellのにviewDidLoad、なぜこのエラーが発生するのですか? このルーチンは、次の init を持つプログラムで動作するようになりました。

self = [super initWithStyle:UITableViewStylePlain]; // in program that does work

一方、動作しないプログラムには初期化があります

self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];   // in program that doesn't work

したがって、上記の 2 つの行は、2 つのプログラムの主な違いです。UITableViewセルに actionBlock が必要なため、セルではなくカスタム セルを使用しました。では、2 番目のプログラムでカスタム セルでエラーが発生するのはなぜですか? CEMBurialCell他のプログラムでも同じカスタム セルが機能します。私は何が欠けていますか?

4

1 に答える 1

0

Your problem is simple. In viewDidLoad, deathstoday is nil so you don't actually register the nib.

Why do you wait until viewWillAppear: to create the table view? You should create the table view in viewDidLoad before your call to registerNib:forCellReuseIdentifier:.

Just be sure to base the table view's frame on self.view.bounds so the autoresizingMask works as expected.

于 2015-12-14T23:29:23.353 に答える