ios - What is the benefit of calling beginUpdates/endUpdates for a UITableView as opposed to not doing so? -


I have an array in which I am using the data source for the table view. In one instance of time, I may have to make some complicated modifications in this data structure. (For example, I need a sequence of operations: delete a line here, enter a line there, insert a section, delete another row, enter a second row, delete another row, enter another section - you think.) It is easy to do this, if for every operation in the sequence, I just update the data source and then update this to see the table immediately. In other words, the pseudocode will look like this:

  [Saranifoda UpdateFor Operation 1]; [Table view updateforest operation 1]; [Arrayfraurerfofooperation2]; [Table view updateOfferation 2]; [Arrayfraa updatefor operation 3]; [Tablewise update operation 3]; [Orofera updatefor operation 4]; [Tablewise update operation 4]; // etc   

However, if I used to "block" these actions in these upgrade / end updates, then this code does not work anymore. To see that imaging starts with seeing an empty table and to insert four rows at the beginning of the first section. This is pseudocode:

  [table view start update]; [ArrayOfArrays insertRowAtIndex: 0]; [Add tableviewRoIndexPath: [line 0, section 0]]; [ArrayOfArrays insertRowAtIndex: 0]; [Add tableviewRoIndexPath: [line 0, section 0]]; [ArrayOfArrays insertRowAtIndex: 0]; [Add tableviewRoIndexPath: [line 0, section 0]]; [ArrayOfArrays insertRowAtIndex: 0]; [Add tableviewRoIndexPath: [line 0, section 0]]; [Table view end update];   

When the endupdates are called, the table view shows that you are entering four rows in four rows!

If we want to keep the initial / end update part of the code, we have to do something complicated (1) we update all the data sources without updating the table view as we go along. (2) Before parts of the data data, how do some parts of the data source show that after all the updates, what updates are needed for the table view. (3) Finally, update the table view in order to complete what we were trying to do in the previous example, the pseudocode looks like this:

  OlderAufAreaz = [Self RecordAfraOfferras] ; // Step 1: [arrayOfArrays insertRowAtIndex: 0]; [ArrayOfArrays insertRowAtIndex: 0]; [ArrayOfArrays insertRowAtIndex: 0]; [ArrayOfArrays insertRowAtIndex: 0]; // Step 2: // Compare the old and new versions of arrayOfArrays, // We think we need to include these index paths: // @ [[line 0, section 0], // [line 1, Section 0], // [row2, section 0], // [row 3, section 0]]; IndexPathsToInsert = [self-comparable and newAreAFRATAOgateIndexPathtoinist]; // Step 3: [Update table start date]; (IndexPathsToInsert in index) {{tableView insertInexPath: indexPath]; } [Table view end update];   

Why do all this for beginners / end updates? The documentation says that to do two things, use beginupdates and last exception to:

  1. insert, delete, and other actions Animate bunch simultaneous
  2. "If you do not include insertion, delete, and select calls within this block, then the row value, such as the table value, may be invalid." (What exactly is this actually anyway?)

    However, if I do not use startUpdates / endupdates, the table view looks like it is animating various changes at once And I do not think the internal stability of the table view is getting corrupted, then what is the benefit of having a complex approach with initial / end updates?

    Every time you add / remove a table item tableView: numberOfRowsInSection: < / Code> method is called - unless you surround these calls with start / endUpdate if your array and table view items are out of synchronization , Then without exception the start / end call will be thrown.

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -