with “viewDidLoad” my viewController take much time to appear!

二次信任 提交于 2019-12-24 01:25:13

问题


when i load my viewController i used "viewDidLoad"method to init my view ,but this take much time to make the view appeared .So i had the idea to use "viewDidAppear" method to accelerate the appearance of my view but the load of the informations about my view are now loaded to the memory every time that i push my view (which is normal) or i pop to it(and there is my problem) Have you an idea?


回答1:


Create a background task that is started in viewDidLoad and just updates the GUI when it's finished. This should at least let you show the GUI, but possibly without valid data.




回答2:


According to the View Controller Programming Guide, you are supposed to create your view in the loadView method :

If you prefer to create views programmatically, instead of using a nib file, you do so from your view controller’s loadView method. You must override this method if you plan to create your views programmatically.

Maybe you should create your view in the loadView method and then load extra data in the viewDidLoad as explained in Understanding the View Management Cycle, using a background task as suggested by willcodejavaforfood if necessary.




回答3:


i did it with the method "ViewDidAppear:animated" and for the problem of loading data for every appearance i deal with it with a test on the top of the mehod:

if(data==nil){/*i do ...*/}

and for me data was an array that i am writing on when loading the view



来源:https://stackoverflow.com/questions/2987672/with-viewdidload-my-viewcontroller-take-much-time-to-appear

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