Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
307 views
in Technique[技术] by (71.8m points)

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...