简体   繁体   中英

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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