Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storyboards and custom container view controllers

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?

NavigationController 'relationship'

Based on my research, it seems like this isn't possible.

like image 242
Stephen Avatar asked Apr 05 '12 14:04

Stephen


1 Answers

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:

enter image description here

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

like image 71
Duncan C Avatar answered Nov 18 '22 19:11

Duncan C