0

テーブル ビュー セルが削除されたときにアニメーションを表示するのに問題があります。アニメーションを表示する唯一のセルは一番下のセルです。テーブル ビューの行数の大小に関係なく、常に一番下のセルです。それが違いを生む場合、グループ化されたテーブルビューセルがあります。[tableView beginUpdates&[tableView endUpdatesブロックや、オンラインで見つけたこのコードを使用するなど、複数のことを試しました。

[UIView beginAnimations:@"myAnimationId" context:nil];

[UIView setAnimationDuration:10.0]; // Set duration here

[CATransaction begin];
[CATransaction setCompletionBlock:^{
    NSLog(@"Complete!");
}];

[myTable beginUpdates];
// my table changes
[myTable endUpdates];

[CATransaction commit];
[UIView commitAnimations];

これは私が現在持っているものです:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        NSLog(@"Recent: %@", self.recentSearchesArray[indexPath.row][0]);

        NSMutableArray *tempMutableArray = [[NSMutableArray alloc] initWithArray:self.recentSearchesArray];
        [tempMutableArray removeObjectAtIndex:indexPath.row];
        self.recentSearchesArray = tempMutableArray;
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

        self.recentSearchesArray = tempMutableArray;   
    }
    [self.tableView reloadData];
}

私が間違っていること、またはこれを修正する方法を知っている人はいますか? ヘルプとガイダンスに感謝します。前もって感謝します。

4

1 に答える 1

0

唯一のセルをリロードするのはどうですか

[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
[tableView endUpdates];

上記はうまくいくはずです。問題は以下のコードにあると思います

オリジナルコード

NSMutableArray *tempMutableArray = [[NSMutableArray alloc] initWithArray:self.recentSearchesArray];
[tempMutableArray removeObjectAtIndex:indexPath.row];
self.recentSearchesArray = tempMutableArray;

あるべき場所

[self.recentSearchesArray removeObjectAtIndex:indexPath.row];
于 2013-11-06T20:51:28.990 に答える