viewDidLoad is called only the first time

早过忘川 提交于 2019-12-11 05:24:55

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!