UITableView allows you to batch editing operations using beginUpdates and endUpdates.
My question is: do I need to know whether it does deletions or insertions first? Or can I refer to everything by the index path prior to beginUpdates and it’ll magically work?
Suppose I have a table:
A (currently index path 0,0)
B (0,1)
C (0,2)
D (0,3)
E (0,4)
F (0,5)
I want to turn it into:
A (0,0)
C (0,1)
D (0,2)
H (0,3)
E (0,4)
F (0,5)
Thus, I’ve deleted B (which was at 0,1) and inserted H (which was inserted after D — at 0,4 before the deletions, or 0,3 after).
So, between my begin/end updates calls, which of these will work?
- deleteRowsAtIndexPaths: 0,1, followed by insertRowsAtIndexPaths:
0,4 - deleteRowsAtIndexPaths: 0,1, followed by
insertRowsAtIndexPaths: 0,3 - insertRowsAtIndexPaths: 0,4, followed by deleteRowsAtIndexPaths: 0,1
- insertRowsAtIndexPaths: 0,3, followed by deleteRowsAtIndexPaths: 0,1
The relevant Apple documentation for this is under Ordering of Operations and Index Paths.
So the table view will first perform any delete or update operations, whose index paths refer to index paths in the original table contents. Then insertions are performed, and those index paths refer to index paths after deletions have occured.
So in theory your number ‘2’ option should be the one you want.