1

再読み込みしたセルと比較して、挿入したセルに異なるスタイルを設定する必要があります。

私は次のようにセルを挿入しています:

[tempArray addObject:[NSIndexPath indexPathForRow:0 inSection:0]];
[[self tableView] beginUpdates];
[[self tableView] insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationTop];
[[self tableView] insertRowsAtIndexPaths:(NSArray *)tempArray withRowAnimation:UITableViewRowAnimationNone];
[[self tableView] endUpdates];

次のことを行う方法はありますか?

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

    if (cell was inserted) {
      cell.mylabel.textColor = [UIColor redColor];
    } else {
      cell.mylabel.textColor = [UIColor blackColor];
    }

}
4

1 に答える 1

2

テーブルビューセルの状態を維持する場合によくあることですが、正しい答えはモデルの状態を維持することです。つまり、tempArrayがテーブルの内容を記述するオブジェクトのコレクションを含むモデルである場合は、これらのオブジェクトにBOOL属性を追加して、のようなものを意味しますuserAdded

次に、「セルが挿入されました」という擬似コードは次のようになります。

MyModelClass *modelElement = [tempArray objectAtIndex:indexPath.row];

if (modelElement.userAdded) {
    cell.mylabel.textColor = [UIColor redColor];
} else {
  cell.mylabel.textColor = [UIColor blackColor];
}
于 2013-01-17T20:29:23.877 に答える