IBOutlet link to embedded container view controller IBOutlet link to embedded container view controller ios ios

IBOutlet link to embedded container view controller


Another option for some cases is to capture the embedded controller using -prepareForSegue:sender:.

For example, if I have a UINavigationController embedded within a CustomContainerViewController, I can name the embed segue embedContentStack in the storyboard and capture it in CustomContainerViewController via

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {    if ([segue.identifier isEqualToString:@"embedContentStack"]) {        // can't assign the view controller from an embed segue via the storyboard, so capture here        _contentStack = (UINavigationController *)segue.destinationViewController;    }}


I'm not sure what you mean by "retrieve the embedded controller". When you want to use a controller you use the UIStoryboard method instantiateViewControllerWithIdentifier:, using the identifier that you give to the controller in IB. You can also use the performSegueWithIdentifier:sender: method (which also instantiated the view controller). You should check out the "Using View Controllers in Your App" section in the Apple docs. It also makes reference to the fact that child view controllers are instantiated at the same time as the container controller.

After edit: If you embed a container view in another view controller, that embedded view's controller can be referenced from the containing controller with self.childViewControllers (which will be an array, so if there is just one, you can get it with lastObject).


Here is another thread about it: Access Container View Controller from Parent iOS

They propose to keep a reference in prepareForSegue or search for the embedded viewController in self.childViewControllers