开发者

viewDidLoad is called only the first time

开发者 https://www.devze.com 2023-01-14 10:11 出处:网络
Maybe someone could tell me why when launch my app in the second time (after pressing the home button) the m开发者_高级运维ethod viewDidLoad: is not being called?On iOS 4 apps are no longer exited whe

Maybe someone could tell me why when launch my app in the second time (after pressing the home button) the m开发者_高级运维ethod viewDidLoad: is not being called?


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.


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


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
0

精彩评论

暂无评论...
验证码 换一张
取 消