Raizlabs/RZCollectionList — pull request #1 by joe-goullaud (2013-01-18 18:34:14+00:00)
Title: RZCollectionListTableViewDataSource breaks for batch updates

Batch updating is broken for a common set of circumstances

Multiple insertions or deletions at the same index are valid on an ArrayCollectionList, because its internal mutable array will be able to shift objects appropriately. However, it then calls out to the table view data source with insertions and deletions at the same cell index path multiple times, which is not valid.

This is especially common on sorted inserts.

#### Example (insertion only)

##### Initial list
- Asparagus
- Banana
- Cucumber

##### Final List
- Apple
- Artichoke
- Asparagus
- Banana
- Cucumber

##### Steps

1. Insert Artichoke: ```[collectionList insertObject:@"Artichoke" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]```
1.1 Array list inserts into mutable array at index 0 **OK**
1.2 Table view data source inserts cell at index path [0, 0] **OK**

2. Insert Apple: ```[collectionList insertObject:@"Apple" atIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]]```
1.1 Array list inserts into mutable array at index 0 **OK**
1.2 Table view data source inserts cell at index path [0, 0] **ERROR**

##### Resolution

The tableview data source, when in batch-update mode, should keep track of what is being inserted and deleted at which indices. When finishing the update, it should compute the final index paths of the cells to delete/add/move based on what operations took place during the batch update, and perform the relevant methods on the table view.

In the example above, two rows should have been inserted at index paths [0,0] and [0,1], since these are the final locations of the objects that were inserted.