0

Interface Builder で作成したカスタム UITableViewCell があります。セルを正常にデキューしていますが、スクロールすると、セルが異なる indexPath を呼び出し始めているように見えます。この例では、現在の indexPath.section と indexPath.row を customCellLabel にフィードしています。テーブルを上下にスクロールすると、一部のセルが変化します。数字はいたるところにありますが、セルは視覚的にスキップしていません。

if(cell==nil) をコメントアウトすると、問題はなくなります。

標準セルを使用すると、問題はなくなります。

なぜこれが起こっているのでしょうか?

// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"CalendarEventCell"];
    if (cell == nil) {
        NSLog(@"Creating New Cell !!!!!");
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CalendarEventCell" owner:self options:nil];
        cell = (UITableViewCell *)[nib objectAtIndex:0];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    }


   // Set up the cell...
  [customCellLabel setText:[NSString stringWithFormat:@"%d - %d",indexPath.section, indexPath.row]];


    return cell;
}
4

1 に答える 1

2

if(cell==nil)条件でセルを作成するとき、そのセルに「CalendarEventCell」としてreuseIdentifierを割り当てていますか? nib 名が CalendarEventCell であることがわかりますが、設定する必要があると思います

cell.reuseIdentifier = @"CalendarEventCell";

そうでない場合、正しいセルをデキューできるかどうかわかりません。また、 customCellLabel が何を指しているのかわかりません。

于 2010-04-22T06:40:20.703 に答える