21
[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:row inSection:0]] 
                      withRowAnimation:UITableViewRowAnimationNone];

在我插入的那一行之后的每一行都执行此操作时会向下滑动。我希望他们立即跳到他们的新地方。我不想打电话reloadData,因为那时我所有的单元格都会被重绘。

是否可以删除此动画?

4

5 回答 5

51

这对我有用:

[UIView setAnimationsEnabled:NO];
[self.tableView beginUpdates];

[self.tableView insertRowsAtIndexPaths:indexPath
                      withRowAnimation:UITableViewRowAnimationNone];

[self.tableView endUpdates];
[UIView setAnimationsEnabled:YES];

希望这可以帮助。

于 2014-06-05T18:55:31.940 回答
15

这也有效

[UIView performWithoutAnimation:^{
    [self.tableView insertRowsAtIndexPaths:indexPaths:withRowAnimation:UITableViewRowAnimationNone];
});
于 2015-11-05T15:13:50.083 回答
2

Swift 示例(来自我的聊天记录)

UIView.performWithoutAnimation {
        messagesTable.insertRows(at: [IndexPath(row: messages.count - 1, section: 0)], with: .none)
    }
于 2020-05-15T10:14:16.447 回答
0

不幸的是,我遇到了同样的问题,我无法删除动画。

必须是 UITableViewRowAnimationNone 动画类型的错误,因为 iOS(任何版本)似乎不尊重它。

于 2012-12-17T22:53:51.317 回答
0

如果更新 UITableView 的 dataSource 并调用[tableView reloadData]而不是手动插入行,则表格将刷新而没有任何动画。

于 2012-12-17T22:59:05.157 回答