9

iOS5 では、ストーリーボードの tableView の ARC とプロトタイプ セルを使用して、以下のコードを置き換えることができます:

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView 
  dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] 
      initWithStyle:UITableViewCellStyleDefault 
      reuseIdentifier:CellIdentifier];
}

// Configure the cell...
return cell;

この簡単なコードで??:

UITableViewCell *cell = [tableView 
  dequeueReusableCellWithIdentifier:@"Cell"];
return cell;

このリンクでこれを見ました:

http://www.raywenderlich.com/5138/beginning-storyboards-in-ios-5-part-1

前もって感謝します!

アリルド

4

2 に答える 2

8

確かに、あなたのコードは正しいです。ストーリーボードは自動的に新しいセルを割り当てます。このコードはうまく機能します:

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

    //Configure cell
    //[cell.lab1 setText:@"Test"];

    return cell;
}
于 2011-11-06T16:37:47.413 に答える
3

これは Apple が意図した使用方法ですが、私は使用しないことをお勧めします。デバイスで VoiceAssist が有効になっている場合、dequeueReusableCellWithIdentifier が nil を返すバグがあります。つまり、このオプションをオンにすると、ユーザーに対してアプリがクラッシュします。これは、iOS 5.1.1 の時点でもまだ問題があります。

詳細情報と回避策は次の場所にあります。

http://hsoienterprises.com/2012/02/05/uitableview-dequeuereusablecellwithidentifier-storyboard-and-voiceover-doesnt-work/

最後の段落には回避策があります

于 2012-05-30T23:03:30.753 に答える