问题
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];
回答1:
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.
来源:https://stackoverflow.com/questions/18427374/uitableview-batch-update-rows