0

いくつかのカスタムセルを使用してテーブルビューを作成しようとしていますが、問題があります。すべてが正しくセットアップされており、このUITableVCを初期VCとして使用すると、すべて機能します。しかし、それを子VCとして別のVCに追加しようとすると、次のエラーが発生します。

Assertion failure in -[UITableView dequeueReusableCellWithIdentifier:forIndexPath:], /SourceCache/UIKit_Sim/UIKit-2372/UITableView.m:4460
2013-02-05 18:37:25.704 SalesBot[16284:c07] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with identifier Statement Cell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'

他には何も変更していません。ストーリーボードの矢印を別のVCに移動して、初​​期化しています。

UITableVCサブクラスを子として別のVCに追加する方法は次のとおりです。

self.statementTableViewController = [[SBStatementTableViewController alloc] init];
[self.view addSubview:self.statementTableViewController.view];
[self.statementTableViewController.view setFrame:self.contentFrame];

そして、これが私がセルをデキューする方法です:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Statement Cell";
    SBStatementCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...

    return cell;
}

上記のコードはiOS6のみであることを理解しています。後で、iOS5について心配します:)

セル識別子はどういうわけか「グローバル」ではなく、別のVCの子である場合、tableVCはそれらを認識できないと思いますか?

さらにコードを確認する必要がある場合は、サポートしてお知らせください。

4

1 に答える 1

0

あなたはまだあなたのコードをフォローアップしていませんが、私はこれがあなたの問題であると確信しています。

取得元: dequeueReusableCellWithIdentifier :forIndexPathでのアサーションの失敗:

dequeueReusableCellWithIdentifier:forIndexPath:メソッドを使用しています。そのメソッドのドキュメントには次のように書かれています。

Important: You must register a class or nib file using the 
registerNib:forCellReuseIdentifier: or registerClass:forCellReuseIdentifier:
method before calling this method.

再利用識別子「Cell」のペン先またはクラスを登録していません。

コードを見ると、提供するセルがない場合、dequeueメソッドがnilを返すことを期待しているようです。その動作には、dequeueReusableCellWithIdentifier:を使用する必要があります。

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

dequeueReusableCellWithIdentifier:とdequeueReusableCellWithIdentifier:forIndexPath:は異なるメソッドであることに注意してください。

于 2013-02-05T16:59:41.313 に答える