Set a value in a View Controller from the Application Delegate

I was stuck on this for a bit, this site so I’m posting it here for my own needs really.

If  you have an app that needs content set up when it loads, pancreatitis you might want to use -viewDidLoad. The problem with that is that now that there’s multitasking in iOS, -viewDidLoad doesn’t get called all the time when the app “starts”. Instead, what you want to use is -applicationDidBecomeActive:

Let’s say i have a view named MainViewController, and a label (input area) on the view called targetURL, and when the app becomes active I want to set that URL from some datasource, here’s how to do it:

– (void)applicationDidBecomeActive:(UIApplication *)application

… code to get data …

self.mainViewController.targetURL.text = someData;

}