1

カスタマイズされたテーブル ビューを使用して Data Core からのデータを表示しています。このように表示されるはずです

ここに画像の説明を入力

しかし、私が実際に持っているのはこれです

ここに画像の説明を入力

これは私のコードです:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [[self.fetchedResultsController sections] count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    id <NSFetchedResultsSectionInfo> sectionInfo = [[self.fetchedResultsController sections] objectAtIndex:section];
    return [sectionInfo numberOfObjects];
}


- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
{
    Item *item = [self.items objectAtIndex:indexPath.row];
    UILabel *nameLabel = (UILabel *)[cell viewWithTag:100];
    nameLabel.text = item.name;
    UILabel *catLabel = (UILabel *)[cell viewWithTag:101];
    catLabel.text = item.category;
    UILabel *amountLabel = (UILabel *)[cell viewWithTag:102];
    amountLabel.text = item.amount;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    static NSString *CellIdentifier = @"AccountCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    [self configureCell:cell atIndexPath:indexPath];

    return cell;

}
4

2 に答える 2

1

セルが存在することがわかりますが、何も入力されていないため、他のデータソース メソッドは機能しています。

この行:

Item *item = [self.items objectAtIndex:indexPath.row];

フェッチされた結果コントローラーを使用している場合は、通常ではありません。そのはず

Item *item = [self.fetchedResultsController objectAtIndexPath:indexPath];

デバッガーをチェックインすると、現在のコードでは項目がおそらく nil であることがわかります。

そうでない場合は、プロトタイプ セルとコードの間でタグが一致しません。繰り返しますが、これはデバッガーで確認できます - ラベルは nil になります。

于 2012-05-10T08:08:40.767 に答える
1

ストーリーボードのラベルを右クリックすると、それらが接続されているアウトレットを確認できます。接続を示す白い点があることを確認し、@jhurton が示唆するように、データ項目が ではないことを確認しますnil

于 2012-05-10T08:19:11.290 に答える