TableView reloadData vs. beginUpdates & endUpdates TableView reloadData vs. beginUpdates & endUpdates ios ios

TableView reloadData vs. beginUpdates & endUpdates


From the UITableView documentation

beginUpdates
Begin a series of method calls that insert, delete, or select rows and sections of the receiver.

That means, you should not use this unless you are inserting, deleting or selecting. You are doing neither of these.

Also, you should end beginUpdates with endUpdates, not reloadData. Documentation:

This group of methods must conclude with an invocation of endUpdates.


The first difference between reloadData and reloadRowsAtIndexPaths is that there are 2 UITableViewCell objects allocated simulteaneosuly for the same indexPath when doing reloadRowsAtIndexPaths (because the tableview 'blends' in the the new cell) . This is sometimes not foreseen by the code in cellForRowAtIndexPath .The surprise comes from the fact that even if a cell was already allocated for a particular cell identfier the table view does not give you back this cell in dequeueReusableCellWithIdentifier when calling reloadRowsAtIndexPaths, instead it returns nil. In contradiction reloadData reuses the cells it already allocated .

The 2nd difference is that endUpdates after reloadRowsAtIndexPaths directly calls cellForRowAtIndexPath (if you set a breakpoint there,endUpdates is visible in the stack trace) whereas reloadData schedules the calls to cellForRowAtIndexPath at a later time (not visible in the stack trace).

However you would need to post a bit more code to give us insight what you are doing there. In principle the indexPaths of the new cells are identical to the old ones also with reloadRowsAtIndexPaths as long as you don't delete or insert rows.


Call this method if you want subsequent insertions, deletion, and selection operations (for example, cellForRowAtIndexPath: and indexPathsForVisibleRows) to be animated simultaneously.

I think this is what you want. beginUpdates & endUpdates can change the UItableview with animation.