在 xib 文件中定义的 UIViewController 不会加载到故事板中 [英] UIViewController defined in a xib file doesn't load in the storyboard

查看:34
本文介绍了在 xib 文件中定义的 UIViewController 不会加载到故事板中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 UIViewController 的子类及其在 xib 文件中定义的视图加载到故事板中.我们称之为 NibViewController.

这种方法的重点是在应用的多个屏幕中重用同一个 ViewController.

我知道可以在代码中手动完成,但我正在故事板中寻找解决方案.我尝试过其他主题的建议,例如

我是否错误地期望 NibViewController 的内容出现在故事​​板中?

解决方案

我是否错误地期望 NibViewController 的内容出现在故事​​板中?

是的,你错了.您的应用运行良好,因此您无需担心并继续操作.

通过从情节提要中的视图控制器中删除视图,您已经明确指示情节提要:不要不要为此视图控制器创建视图.在运行时,视图应该来自 em>xib 文件,不是你的."

而这正是运行时所做的.因此,只需在 xib 文件中设计您的界面,一切都会好起来的.

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?

解决方案

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.

这篇关于在 xib 文件中定义的 UIViewController 不会加载到故事板中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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