What order do batched row insertions/deletions take place in UITableView?

Viewed 1080

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?

  1. deleteRowsAtIndexPaths: 0,1, followed by insertRowsAtIndexPaths: 0,4
  2. deleteRowsAtIndexPaths: 0,1, followed by insertRowsAtIndexPaths: 0,3
  3. insertRowsAtIndexPaths: 0,4, followed by deleteRowsAtIndexPaths: 0,1
  4. insertRowsAtIndexPaths: 0,3, followed by deleteRowsAtIndexPaths: 0,1
1 Answers
Related