Storyboards and custom container view controllers

偶尔善良 提交于 2019-11-28 06:56:03

It IS possible to link a container view controller to a child. In fact, it's trivially easy to do so. You bring up the Object library, type "Container" into the search field, and look for the object "Container view". It looks like this:

Drag a container view into your view controller's content view.

Then you control-drag from the container view onto the other view controller that you want the container view to host. IB sets up an "embed segue" for you. The embed segue gets invoked when the parent view controller's content view is loaded. The embed segue sets up the parent/child view controller relationship and does the housekeeping you need. It's easy and painless.

Your prepareForSegue method is called for each embed segue. You can assign unique identifiers to your embed segues just like other segues, and then use the segue ID in your prepareForSegue to do extra setup for the child view controller.

Take a look at this project on github that shows how to use embed segues to include 2 static UITableViewControllers in a parent using container views and embed segues. This project sets up custom protocols for the parent and child VCs to communicate with each other. In the prepareForSegue method the parent saves pointers to both child VCs, and also sets itself up as delegates of both child VCs so the child can communicate back to the parent.

You can find the project at this link: https://github.com/DuncanMC/test

You can use Container Views for it. Container View creates relationship to the new view controller automatically.

Have you tried subclassing the UITabbarcontroller or UINavigationController?

You can create your custom class extending from one of these and then set it in your storyboard - thus allowing you to create the same relationships. Then you can hide the tabbar and add whatever functionality you want.

I haven't done this but it's an interesting problem. Did you define your child view controllers in your container controller before trying associate them in the storyboard (you may be doing this - no code is shown)? From the docs it sounds like that is what you need to do - it may be that it is not like with the generic classes where you can just drag them in.

In order for iOS to route events properly to child view controllers and the views those controllers manage, your container view controller must associate a child view controller with itself before adding the child’s root view to the view hierarchy.

Anyway - a guess...

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