如何从故事板以编程方式延迟加载视图 [英] How to lazy load views programmatically from storyboards

查看:27
本文介绍了如何从故事板以编程方式延迟加载视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以前版本的 Interface Builder 中,当我想以编程方式延迟加载视图时,我会执行以下操作:

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).

我有一个管理多个视图的视图控制器.我不希望它们都加载到 viewDidLoad 上,所以我不想将它们包含在视图控制器的笔尖中.还有其他方法吗?如果没有,我仍然可以创建笔尖并仍然使用 loadNibNamed.有人可以建议混合笔尖和故事板是否是一种合适的策略?Apple 不允许在故事板中加载这种视图,这一事实让我有点担心.

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.

推荐答案

有人可以建议混合笔尖和故事板是否是一种合适的策略?

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

XIBS 和故事板并不相互排斥.没有理由不应该在同一个应用程序中同时使用两者.我实际上在同一个应用程序中使用了多个 Storyboard 和 xib.工作正常.

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.

这篇关于如何从故事板以编程方式延迟加载视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆