gpt4 book ai didi

ios - 如何在加载时为 UITableView 中的行设置动画?

转载 作者:行者123 更新时间:2023-11-29 13:30:33 25 4
gpt4 key购买 nike

我想将 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呢?

最佳答案

您应该看看 beginUpdatesendUpdates。在这两个命令中,您可以更新/删除/插入行并为您设置动画。它也比使用 reloadData 更有效率。

更多关于此主题的信息:http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

快速摘录:

  • (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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com