0

このチュートリアルに従おうとしていますが、空のテーブルが表示されます。

http://www.techotopia.com/index.php/Using_Xcode_5_Storyboards_to_Build_Dynamic_TableViews_with_Prototype_Table_View_Cells

まず、チュートリアルは使用しています

{
CarTableViewCell *cell = [tableView 
      dequeueReusableCellWithIdentifier:CellIdentifier 
      forIndexPath:indexPath];
}

これでエラーが発生しました:

2013-11-12 11:29:35.940 TableViewStory[14940:70b] *** Terminating app due to uncaught 
exception 'NSInternalInconsistencyException', reason: 'unable to dequeue a cell with 
identifier carTableCell - must register a nib or a class for the identifier or connect a 
prototype cell in a storyboard'

だから私は追加しました:

[self.tableView registerClass:[CarTableViewCell class] 
    forCellReuseIdentifier:@"carTableCell"];

私のviewDidLoadで。registerClass を追加した後、アプリケーションをビルドすることができました。しかし、私は空のテーブルを取得しています。

ありがとうございました。

4

2 に答える 2

0

チュートリアルをやり直したところ、すべてうまくいきました。

とにかくありがとう。

于 2013-11-12T11:27:01.117 に答える
0

cellForRowAtIndexPath メソッドを適切に実装する必要があります。

- (UITableViewCell *)tableView:(UITableView *)iTableView cellForRowAtIndexPath:(NSIndexPath *)iIndexPath
{
    static NSString *cellIdentifier = @"Cell";

    UITableViewCell *cell = [iTableView dequeueReusableCellWithIdentifier:cellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
    }

// Customize your cell

return cell;
}

再利用識別子 CellIdentifier の nib またはクラスを登録していません。以下のピースを使用しています

CarTableViewCell *cell = [tableView 
      dequeueReusableCellWithIdentifier:CellIdentifier 
      forIndexPath:indexPath];

これを

CarTableViewCell *cell = [tableView 
          dequeueReusableCellWithIdentifier:CellIdentifier];
于 2013-11-12T03:40:57.727 に答える