Reputation: 635
When is the best time to call [reloadData] on a UITableView? viewDidAppear or viewWillAppear? If a view is unloaded, will the underlying tableview be unloaded as well?
The reason I am asking is due to some behavior I am seeing. Let's say a view is asked to reload its datasource, but is deallocated before it can finish. A scenario would be with a UITabBarController and navigating to a different view than the ViewController being selected. So what happens is that viewWillAppear gets called, but viewDidAppear does not (since I navigated away).
As a result, the ViewController gets deallocated (along with its model data), but if I am calling reloadData in viewWillAppear, the "cellForRow", and "numberOfRows" methods are invoked which causes a "deallocated instance" error. Does that make sense? Do you normally put in code that checks for nil if the model can be changed anytime the view is requested to appear?
Upvotes: 2
Views: 2382
Reputation: 1
before you get the datasource from server or anywhere, you can display the tableview with a blankcell(a cell that you can draw sth like 404 web page) , when you get the data, then reload the tableview. remember to set number of cell to 1 for the blankcell
Upvotes: 0
Reputation: 1000
I would load the table once the view has loaded, it allows for all of the UIObjects to be created before messing with them. Not sure, but I believe the table is automatically unloaded with the superview.
Take a look at this question>>> Objective C - Correct way to empty and reload UITableViewController with NSMutableArray
Upvotes: 0