So I have a UITableView in which I am doing batch insert/delete/reloads into. Every once in a while, the list data changes, so I batch update the differences in the list. I’m basically inserting new rows, deleting rows that are no longer there, and reloading rows that exist in both the old and new data. For example:
Before, the list data looks like this:
0: apple
1: banana
2: carrot
After, the list data looks like this:
0: banana
1: carrot
2: dog
3: elephant
This results in deleting row 0, reloading rows 1 and 2, and inserting at rows 2 and 3. The order I call the methods is also in this way: delete, then reload, then insert rows.
However, this results in a exception being thrown since I’m doing two different animations on row 2 (reloading and inserting). Is this an ordering issue, or are my indexPaths incorrect? Note: I need to reload old cells, since the data for that row may have changed, but should not be represented by an insertion/deletion.
Edit: Weirdly enough, this error only happens in iOS versions earlier than iOS4.
I’d say delete 0, and insert 3 and 4. Reloading shouldn’t be needed. The order in which you send the updates is irrelevant. Make sure that your model reflects the changes before you tell about the updates. Wrap the calls up with -beginUpdates: end -endUpdates:.
Here is a link for batch update, see listing 7-8:
https://developer.apple.com/library/content/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW16
The WWDC video hint is good, too. You want to look out for Session 128 – Mastering Table Views.