UITableView reloadData and cellForRowAtIndexPath - interrupted?

Suppose there is a UITableView called myTable. Let them say that the following sequence of events occurs -

  • The table is full.

  • The data source has been updated (in this case sqlite3 db, but it doesn’t really matter), NSNotifcation means there is new data, the main stream receives a notification, and then calls [myTable reloadData].

  • myTable UITableViewDataSource numberOfSectionsInTableView is called. Suppose only 1 section.

  • myTable UITableViewDataSource tableView:numberOfRowsInSection: called.

  • Multiple tableView:cellForRowAtIndexPath: receive a call based on the number of rows in the data source.

My question is related to interruption cellForRowAtIndexPath.

Question -

If "reloadData" is called and cellForRowAtIndexPath is called. Another reboot is in progress. Will cellForRowAtIndexPath stop in the middle and restart after calls to numberOfSectionsInTableView and numberofRowsInSection?

Or will there be a new reload of the Date queued, so that all the cellForRowAtIndexPaths properties will end before both the OffsectionsInTableView and numberOfRowsInSection are called?

I looked and could not find the answer to this question in the documents or on the network. I am concerned that if the data store is being updated and cellForRowAtIndexPaths is “running”, the numerical value of OfSectionsInTableView may change, which could cause cellForRowAtIndexPath to request data for a cell that is now out of range.

Any help would be greatly appreciated.

+4
source share
2 answers

Since you should only call reloadData in the main thread, and since all visible cells are already loaded by the time reloadData , there is nothing to worry about. The second call to reloadData will be made after the first is completed.

+2
source

I don’t think you can be in the middle of cellForRowAtIndexPath when reloadData is called provided that both of them are called in the same (main) thread (having asynchronous processing in the background thread in cellForRowAtIndexPath seems pointless).

+1
source

Source: https://habr.com/ru/post/1501710/


All Articles