When is an IBOutlet UIViewController inited, if set as a property? How to optimize IBOutlet UIViewControllers' loading?

风流意气都作罢 提交于 2021-02-09 00:24:59

问题


I have my main app view controller (File's Owner), its First Responder, View, and 3 other UIViewControllers in the same nib file. Every one of the 3 UIViewControllers is referenced on the main UIViewController as an IBOutlet.

My question is, when does the main UIViewController init those 3 UIViewControllers, in its life cycle (my guess is sometime before calling viewDidLoad) and should I worry with optimizing how and when they are loaded. The reasoning is obviously that if the app loads the main view controller and then right away starts loading the other view controllers, the user might have to wait for everything to get loaded first. But if I could still have the IBOutlets synthesized, but have the option to decide when those view controllers (and their views) are loaded, then this would definitely be an improvement.


回答1:


The UIViewController doesn’t initialize the outlets, that’s done by the nib loading code before awakeFromNib and viewDidLoad. Anything that is in one nib file gets loaded, instantiated and intialized at the same time. So as long as your views are in the same nib there is no way to load them on demand. You should put the other views in different nib files and load them when they are needed. Putting everything in one nib is not a good idea.



来源:https://stackoverflow.com/questions/3817879/when-is-an-iboutlet-uiviewcontroller-inited-if-set-as-a-property-how-to-optimi

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