如何以编程方式从故事板延迟加载视图
在以前版本的 Interface Builder 中,当我想以编程方式延迟加载视图时,我会执行以下操作:
self.customView = [[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:nil];
如果我理解正确,这是正确的方法。似乎没有办法用故事板来做到这一点,因为没有办法将视图添加到故事板本身(而不是视图控制器的一部分)。
我有一个管理多个视图的视图控制器。我不希望它们全部加载到 viewDidLoad 上,所以我不想将它们包含在视图控制器的笔尖中。还有别的办法吗?如果没有,我仍然可以创建笔尖并仍然使用 loadNibNamed。有人可以建议这是否是混合笔尖和故事板的适当策略?事实上,苹果不允许在故事板中加载这种视图,这让我有点担心。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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.