问题
Maybe someone could tell me why when launch my app in the second time (after pressing the home button) the method viewDidLoad:
is not being called?
回答1:
On iOS 4 apps are no longer exited when pressing the home button. They are moved out of RAM, paused and then continued when you re-enter them, not launched again.
回答2:
In iOS4 there is:
- (void)applicationDidBecomeActive:(UIApplication *)application { }
Which is called when the application becomes active (out of background) you could call things from here that need to happen when you open the app.
Thanks James
回答3:
The second time you "launch" your application, in fact you are not launching but only re-activating (your application was in background). Your views are not reloaded.
As said in the previous answers :
- You can detect it via
(void)applicationDidBecomeActive:(UIApplication *)application
and execute some code here (refresh HMI, refetch datas, etc...), - Or move your code to
viewWillAppear
来源:https://stackoverflow.com/questions/3586416/viewdidload-is-called-only-the-first-time