我想将 UITableViewRowAnimation 与 :reloadData 结合使用。
在我使用该示例进行表加载之前(我在一些 ios 开发指南中发现):
for (NSDictionary *entry in [dl reverseObjectEnumerator]) {
int insertIdx = 0;
[_allEntries insertObject:entry atIndex:insertIdx];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:insertIdx inSection:0]]
withRowAnimation:UITableViewRowAnimationRight];
}
但是这种方式在大数据上似乎真的很慢,那么如何快速加载带有动画的tableviews呢?
最佳答案
您应该看看 beginUpdates
和 endUpdates
。在这两个命令中,您可以更新/删除/插入行并为您设置动画。它也比使用 reloadData
更有效率。
快速摘录:
- (void)beginUpdates
Call this method if you want subsequent insertions, deletion, and selection operations (for example, cellForRowAtIndexPath: and indexPathsForVisibleRows) to be animated simultaneously. This group of methods must conclude with an invocation of endUpdates. These method pairs can be nested. If you do not make the insertion, deletion, and selection calls inside this block, table attributes such as row count might become invalid. You should not call reloadData within the group; if you call this method within the group, you will need to perform any animations yourself.
关于ios - 如何在加载时为 UITableView 中的行设置动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12011229/