简体   繁体   English

xib文件中定义的UIViewController不会加载到情节提要中

[英]UIViewController defined in a xib file doesn't load in the storyboard

I'm trying to load a subclass of a UIViewController with its views defined in a xib file into a storyboard. 我正在尝试将xib文件中定义的视图的UIViewController的子类加载到情节提要中。 Let's call it a NibViewController. 我们称之为NibViewController。

The point of this approach is to reuse the same ViewController in multiple screens of the app. 这种方法的重点是在应用程序的多个屏幕中重用相同的ViewController。

I know it's possible to do it manually in the code, but I'm looking for a solution in the storyboard. 我知道可以在代码中手动完成此操作,但是我正在寻找情节提要中的解决方案。 I've tried suggestions from other topics like this one , but nothing worked. 我试图从其他的主题,例如建议这一个 ,但毫无效果。 The ViewController is correctly displayed in the simulator but not in the storyboard. ViewController正确显示在模拟器中,但未显示在情节提要中。 Here is the code: https://github.com/srstanic/NibViewControllerInStoryboard and here is the screenshot: 这是代码: https : //github.com/srstanic/NibViewControllerInStoryboard ,这是屏幕截图:

在此处输入图片说明

Am I mistaken to expect the contents of the NibViewController to appear in the storyboard? 我是否误以为NibViewController的内容会出现在故事​​板上?

Am I mistaken to expect the contents of the NibViewController to appear in the storyboard? 我是否误以为NibViewController的内容会出现在故事​​板上?

Yes, you are mistaken. 是的,你错了。 Your app is working perfectly so you should stop worrying and just proceed. 您的应用程序运行良好,因此您不必担心,只需继续即可。

By deleting the view from the view controller in the storyboard, you have specifically instructed the storyboard: "Do not make a view for this view controller. At runtime, the view should come from the xib file, not from you." 通过删除故事板视图控制器的看法,你已经明确指示情节提要:“ 不要让这个视图控制器视图在运行时,认为应该来自XIB文件,而不是你。”

And that is exactly what does happen at runtime. 而这也正是在运行时发生。 So just design your interface in the xib file and all will be well. 因此,只需在xib文件中设计您的界面,一切都会很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM