How to lazy load views programmatically from storyboards

余生长醉 提交于 2019-12-08 08:03:28

问题


In previous versions of Interface Builder, when I want to lazy load views programatically, I would do something like:

self.customView = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil];

If I understand correctly, this was the proper way to do it. There does not seem to be a way to do this with storyboards, as there is no way to add a view into the storyboard itself(without being part of a view controller).

I have a view controller that manages multiple views. I do not want them all to be loaded on viewDidLoad, so I'd rather not include them in view controller's nib. Is there another way? if not, I could still create nibs and still use loadNibNamed. Can someone advise on whether this is an appropriate strategy, to mix nibs and storyboards? The fact that Apple has disallowed this kind of view loading in storyboards makes me slightly worried.


回答1:


Can someone advise on whether this is an appropriate strategy, to mix nibs and storyboards?

XIBS and Storyboards are not mutually exclusive. There is no reason why you should not use both in the same application. I'm actually using multiple Storyboards and xibs in the same application. Works fine.



来源:https://stackoverflow.com/questions/9161722/how-to-lazy-load-views-programmatically-from-storyboards

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