1

我在 iOS 中创建了一个表格视图并实现了删除行功能。一切正常。我有一个疑问,

考虑以下情况,

假设表格有 15 行,如果我删除第 10 行。有时顶部 (1-9) 的单元格从上到下动画到第 10 行的位置。有时底部的单元格 (11-15)动画到顶部。这是随机发生的。

这是删除的代码

- (void)tableView:(UITableView *)tableView
commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);

if (editingStyle == UITableViewCellEditingStyleDelete)
{
    [[self contents] removeObjectAtIndex:[indexPath row]];

    NSArray *indexPathsToRemove = [NSArray arrayWithObject:indexPath];

    [tableView deleteRowsAtIndexPaths:indexPathsToRemove     withRowAnimation:UITableViewRowAnimationAutomatic];
}

NSLog(@"<<< Leaving %s >>>", __PRETTY_FUNCTION__);
}

在这之间是我正在关注的教程

您可以从此链接下载该项目。

反正有没有控制这种行为。

提前致谢

4

1 回答 1

0

你可以控制它

withRowAnimation:UITableViewRowAnimationAutomatic

有多种选择

UITableViewRowAnimationBottom
UITableViewRowAnimationFade
UITableViewRowAnimationRight
...

实际方法是:

    [mainTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic]; 
于 2013-11-12T06:35:07.447 回答