Wednesday, 11 September 2013

UITableView reloadData and cellForRowAtIndexPath - interruptable?

UITableView reloadData and cellForRowAtIndexPath - interruptable?

Let's assume there exists a UITableView called myTable. Let's say the
following sequence of events occur --
Table is fully populated.
The data source is updated (in this case an sqlite3 db, but doesn't really
matter), an NSNotifcation happens to indicate that there is new data, the
main thread receives the notification and then calls [myTable reloadData].
myTable's UITableViewDataSource's numberOfSectionsInTableView gets called.
Assume only 1 section.
myTable's UITableViewDataSource's numberOfRowsInSection gets called.
Several cellForRowAtIndexPath's get called depending on the number of rows
in the data source.
My question has to do with the interruptability of cellForRowAtIndexPath.
The question --
If a "reloadData" is called and cellForRowAtIndexPath's are getting called
AND another reloadData comes in, will the cellForRowAtIndexPath's stop
midstream and restart after the calls to numberOfSectionsInTableView and
numberofRowsInSection?
Or will the new reloadData be queued, such that all of the
cellForRowAtIndexPaths will finish BEFORE the numberOfSectionsInTableView
and numberOfRowsInSection get called?
I've looked and have been unsuccessful in finding an answer to this
question in docs or the net. I'm concerned that if the data store is
updated while the cellForRowAtIndexPaths are "running", the
numberOfSectionsInTableView can change which can result in the
cellForRowAtIndexPath requesting data for a cell that's now out of range.
Any help would be greatly appreciated.

No comments:

Post a Comment