0

行を移動した後、セルに関連付けられているビジネスの lineandPin 番号を変更しました。cellForRowAtIndexpath が再度呼び出されると、うまくいくでしょう。

ここに画像の説明を入力

これは私のコードです

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    NSMutableArray *  mutableBusinessBookmarked= self.businessesBookmarked.mutableCopy;
    Business *bizToMove = mutableBusinessBookmarked[sourceIndexPath.row];
    [mutableBusinessBookmarked removeObjectAtIndex:sourceIndexPath.row];
    [mutableBusinessBookmarked insertObject:bizToMove atIndex:destinationIndexPath.row];
    self.businessesBookmarked=mutableBusinessBookmarked;
    [self rearrangePin];
    [tableView moveRowAtIndexPath:sourceIndexPath toIndexPath:destinationIndexPath];
    [self.table reloadData];
}
  1. 私はそれを正しく行っているかどうかわかりません。データモデルと呼び出しを更新しましたmoveRowAtIndexPath
  2. [tableView moveRowAtIndexPath...何もしないようです。私がそれを呼び出すかどうかにかかわらず、行は移動されます。
  3. self.table reloadData の呼び出しは賢明ではないと思います。ただし、左の数字を更新したい。cellForRowAtindexpathを呼び出してもまだ呼び出されませんself.table reloadData
4

1 に答える 1

3

セル構成ロジックを別のメソッドに移動することをお勧めします。次に、moveRowAtIndexPathこのメソッドを直接呼び出して、表示されているセルを更新できます。例えば:

- (void)configureCell:(UITableViewCell *)cell
{
    NSIndexPath *indexPath = [self.tableView indexPathForCell:cell];
    // Get data for index path and use it to update cell's configuration.
}

- (void)reconfigureVisibleCells
{
    for (UITableViewCell *cell in self.tableView.visibleCells) {
        [self configureCell:cell];
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"MyCellIdentifier"];
    [self configureCell:cell];
    return cell;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
    // Update data model. Don't call moveRowAtIndexPath.
    [self reconfigureVisibleCells];
}

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self configureCell:cell];
}

いくつかの追加コメント:

  1. cellForRowAtIndexPathテーブル ビューが新しいセルを表示する必要がある場合にのみ呼び出されます。可視セルに対して呼び出されることはありません。
  2. moveRowAtIndexpathデータ モデルが変更され、その変更を UI に伝達する必要がある場合に呼び出すのが適切です。あなたのケースはこれの逆です。つまり、UI はデータ モデルへの変更を伝達しています。だからあなたは電話しないでしょうmoveRowAtIndexPath
  3. willDisplayCellの後にテーブル ビューがカスタマイズを上書きする場合があるため、常にセルを再構成しますcellForRowAtIndexPath
于 2013-01-20T02:22:38.197 に答える