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

白昼怎懂夜的黑 提交于 2019-12-11 15:31:36

问题


I'm trying to load a subclass of a UIViewController with its views defined in a xib file into a storyboard. Let's call it a NibViewController.

The point of this approach is to reuse the same ViewController in multiple screens of the app.

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. Here is the code: https://github.com/srstanic/NibViewControllerInStoryboard and here is the screenshot:

Am I mistaken to expect the contents of the NibViewController to appear in the storyboard?


回答1:


Am I mistaken to expect the contents of the NibViewController to appear in the storyboard?

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

And that is exactly what does happen at runtime. So just design your interface in the xib file and all will be well.



来源:https://stackoverflow.com/questions/47229338/uiviewcontroller-defined-in-a-xib-file-doesnt-load-in-the-storyboard

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