I'm creating a custom container view as per the apple spec. I would like to use the storyboard to connect three static child UIViewControllers. Is there an easy way in the storyboard to connect via a Relationship
as seen for the UINavigationController in the storyboard?
Based on my research, it seems like this isn't possible.
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...
来源:https://stackoverflow.com/questions/10031035/storyboards-and-custom-container-view-controllers