In what order are row inserts / deletes inserted into a UITableView?

UITableView allows you to perform batch editing operations using beginUpdates and endUpdates .

My question is: should I first know if this is really done for deletion or insertion? Or can I reference everything along the index path to beginUpdates , and it will 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) 

So I deleted B (which was at 0.1) and inserted H (which was inserted after D - 0.4 before removal, or 0.3 after).

So, between my calls to the start / end of the update, which one will work?

  • deleteRowsAtIndexPaths: 0.1 and then 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
+8
ios cocoa-touch uitableview
source share
1 answer

The relevant Apple documentation for this is under Ordering Operations and Guide Points .

The delete and reload operations in the animation block determine which rows and partitions in the source table should be deleted or reloaded; insertion indicate which rows and sections should be added to the table . Index paths used to identify partitions and strings follow this model.

Thus, the table view will first perform any delete or update operations whose index paths refer to the index path in the original contents of the table. Insertions are then performed, and these pointer paths refer to the index paths after deletion.

So, theoretically, your number "2" should be the one you need.

+8
source share

All Articles