I've noticed that viewDidLoad of the viewController will not run if the app has been "minimized" in the iOS multitasking state, and then开发者_JAVA技巧 you re-open it. It defaults to the last view, with none of the initialization of viewDidLoad.
I'd be interested in making sure that some piece of code always runs whenever the app is launched. Now I read here that perhaps the appDelegate is the place for this. Before I re-arrange my code to move things from viewDidLoad to the application delegate, I thought I'd check here first to make sure there isn't any other option.
Can't you use the viewWillAppear:(BOOL) animated method ?
I sense a little broken MVC here. viewDidLoad
method is a place to setup view objects to display data initialized in controller's init methods or launch some asynchronous or delegated task which depends on IBOutlets and views being loaded.
Putting code, that app depends on without views being loaded, into method that is mostly for preparing view specific things - is not a good idea. You should definitely check out app delegate methods for this.
Also viewDidLoad
will be called if the view was unloaded. Can you confirm that viewDidUnload
was called when you minimized your app?
Look at the UIApplicationDelegate methods. You can be notified when the application resumes from background.
applicationDidBecomeActive:
applicationWillEnterForeground:
精彩评论