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

1

11

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

Blistery answered 7/11, 2013 at 2:11 Comment(1)
"The goal is to have TransitVC hold AutocompleteVC inside autocompleteContainerView." -- what do you mean by this? You already have a view controller embedded in autocompleteContainerView, so what's the problem?Allot
Z
6

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.

Zayin answered 7/11, 2013 at 3:31 Comment(1)
I understand exactly what guptron is asking. The issue is that the child View Controller which is embedded in the Container View fills the Container View perfectly, but any children of the embedded View Controller will not be "contained" in the Container View. They instead will fill the screen. I wish I knew what the answer was - I'm actually looking for this same answer myself.Thermion

© 2022 - 2024 — McMap. All rights reserved.