Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In iOS, using storyboard, how to setup a view controller inside a container view?

I have created and drawn out a custom UIViewController called AutocompleteVC in my Main storyboard. AutocompleteVC will be used in several different places/storyboards and with different dimensions.

For example, in my Transit storyboard, shown below,, there is a custom UIViewController called TransitVC, shown on the left. In TransitVC, I have a container view with an IBOutlet called autocompleteContainerView. autocompleteContainerView has a segue called autocompleteEmbedSegue to a generic UIViewController, shown on the right in red.

The goal is to have TransitVC hold AutocompleteVC inside autocompleteContainerView. But I'm having trouble getting this to work. The reason I want to do this inside a container view is so I can use autolayout to set constraints on it. Otherwise, I know how to do this purely in code.

I believe my approach might be flawed. What is the correct approach to do this if I want to maximize storyboard usage.

enter image description here

like image 497
abc123 Avatar asked Nov 07 '13 02:11

abc123


People also ask

How do I embed a view controller in navigation controller storyboard?

Storyboard setup In your storyboard, select the initial view controller in your hierarchy. With this view controller selected, choose the menu item Editor -> Embed In -> Navigation Controller .

How do I add a container view to a storyboard?

Add a child view controller programmatically to your contentCall the addChild(_:) method of your container view controller to configure the containment relationship. Add the child's root view to your container's view hierarchy. Add constraints to set the size and position of the child's root view.


1 Answers

I'm not sure what you are asking. Setting up a parent/child relationship with a container view is very easy, exactly as you have outlined. Just create a container view inside the parent view controller, create the child view controller scene, and then control-drag from the container view to the child view controller to create the embed segue.

like image 163
Duncan C Avatar answered Oct 25 '22 08:10

Duncan C