Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
301 views
in Technique[技术] by (71.8m points)

objective c - UITableView batch update rows

By updating the table, is there a difference, when i call let's say insertRowsAtIndexPaths more times, with an array of 1 object, comparing to calling it once, with an array of all objects?

This question also applies to reload, and delete, not just insert

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];

Comparing to

[self.tableView insertRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:1 inSection:sectionIndex], [NSIndexPath indexPathForRow:2 inSection:sectionIndex], [NSIndexPath indexPathForRow:3 inSection:sectionIndex]] withRowAnimation:UITableViewRowAnimationFade];
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...