What exactly does reloadData call?
When calling reload开发者_运维百科Data on a UITableView what methods are actually invoked?
[tableView reloadData];
The whole table view is reloaded, it calls cellForRowAtIndexPath to get the cells for all your rows and sections...doing so it also calls numberOfSections method of tableView datasource and numberOfRows method of tableview data source etc etc
Also, for future reference, that information is readily available in the documentation here. Copy/pasted from Apple's documentation:
Call this method to reload all the data that is used to construct the table, including cells, section headers and footers, index arrays, and so on. For efficiency, the table view redisplays only those rows that are visible. It adjusts offsets if the table shrinks as a result of the reload. The table view's delegate or data source calls this method when it wants the table view to completely reload its data. It should not be called in the methods that insert or delete rows, especially within an animation block implemented with calls to beginUpdates and endUpdates
For the accept answer is very good. But I want to mention all the visible cells will be recreated. Usually this not a big deal. But if your tableViewCell stored property contains some data might be lost.
For example, click a button on a tableViewCell to request some data from internet and saved the retrieved data to a stored property. If you reloadData
, then the retrieved data will lost. Of course this is not a proper actually make a request from tableViewCell. But just want to explain this situation.
精彩评论