I am struggling a little bit with the lifecycle of a UIViewController.
Basically, I have an application that consists of a UINavigationController, that has currently an UITableViewController as the root view controller.
The UITableView of this UITableViewController is updated with an asynchronious call to a web service.
Up to that point, everything works fine!
In general, I would like the UITableViewController to reload the data for the TableView every time the ViewController is shown.
That means, if I dismiss the app and start another app and then return to my application the data should be always reloaded from the web service. Basically, like the Twitter app as an example that updates the tweets each time when the app is restarted.
To achieve this, I placed the call to the web service in different places to test the behavior.
I tried, viewDidLoad, viewWillAppear & viewDidAppear but all of these methods are just called once when the viewController is created.
I did some research here in stackoverflow and there was the hint to use NSNotification applicationDidBecomeActive which does work but I am not sure if this is the proper solution if I add more ViewControllers to my app in future because I want the update of the viewController only when this controller is also shown/visible to the user.
Any suggestions on this issue are highly welcome!
Thanks a lot
Neo74
There is nothing wrong using
applicationDidBecomeActiveto update the information from the web services, and if you are planning to add more view controllers in the future, it is even better to have to web services logic outside of a single view controller.What you shouldn’t do is put the code to access your WS inside the application delegate, instead create a singleton class responsible of this.