UITableView批处理更新行 [英] UITableView batch update rows

查看:66
本文介绍了UITableView批处理更新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过更新表,是否有区别,当我说一次用一个对象数组调用insertRowsAtIndexPaths而不是一次用所有对象数组调用insertRowsAtIndexPaths时

此问题也适用于重新加载和删除,而不仅仅是插入

这看起来像是一个琐碎的问题,但是更新机制非常复杂,尤其是如果您混合使用插入,删除,重新加载并且不确定这是否会影响动画

This may look like a trivial question, but the update mechanism is quite complex, especially if you mix inserts, deletes, reloads and not sure if this can affect the animation

[self.tableView beginUpdates];

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:sectionIndex]] withRowAnimation:UITableViewRowAnimationFade];

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:2 inSection:sectionIndex]] withRowAnimation:UITableViewRowAnimationFade];

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:3 inSection:sectionIndex]] withRowAnimation:UITableViewRowAnimationFade];

[self.tableView endUpdates];

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:sectionIndex], [NSIndexPath indexPathForRow:2 inSection:sectionIndex], [NSIndexPath indexPathForRow:3 inSection:sectionIndex]] withRowAnimation:UITableViewRowAnimationFade];

推荐答案

在begin/commitUpdate调用之间没有区别.

There isn't a difference as long as you do it between the begin/commitUpdate calls.

The exact methods are described in the TableView Programming Guide, in the section called "Ordering of operations and Index Paths"

动画块中的删除和重新加载操作指定应删除或重​​新加载原始表中的哪些行和节;插入指定应将哪些行和节添加到结果表中.用于标识节和行的索引路径遵循此模型.另一方面,在可变数组中插入或删除项目可能会影响用于后续插入或删除操作的数组索引;例如,如果您在某个索引处插入项目,则数组中所有后续项目的索引都会增加.

Deletion and reloading operations within an animation block specify which rows and sections in the original table should be removed or reloaded; insertions specify which rows and sections should be added to the resulting table. The index paths used to identify sections and rows follow this model. Inserting or removing an item in a mutable array, on the other hand, may affect the array index used for the successive insertion or removal operation; for example, if you insert an item at a certain index, the indexes of all subsequent items in the array are incremented.

这篇关于UITableView批处理更新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆