To create a parent / child relationship between two view managers from code, this basically matters:
[self addChildViewController:childViewController]; [self.view addSubview:childViewController.view];
where self is the parent view controller.
But, what if I want to completely create the same relationship from Interface Builder?
Or, in other words: is there a way to recreate the behavior of the addChildViewController method using Interface Builder? I did not find much documentation about this, here is an old unresolved article about the topic: https://devforums.apple.com/message/455758#455758
Without properly setting the addChildViewController relationship, none of the rotation methods are redirected to my child view controller, here, where my question arises.
This is what I did at IB:
- drag the View Controller object from the Object Library panel to the Objects panel
- in the identity inspector I changed my class to my subclass of UIViewController ("Element Presentation Controller")
- connected the outlet to the controller.
- connected all other required outputs with the controller (list name, table view)
The first “View” object in the image is the view of my parent view controller, instead, the highlighted “View” is the view of the child view controller (“Item View Controller”).

The container controller also saves the child instance through an optional IBOutlet:
@property (nonatomic, strong) IBOutlet ItemsViewController *itemsViewController;
thanks
Update 1: If I manually set the parent / child relationships in the viewDidLoad of the container controller, all rotation methods will be correctly redirected to the child.
[self addChildViewController:self.itemsViewController]
But I really do not know if this is being done correctly, since I would like to do everything with IB.
Update 2: Thanks to @micantox, for his help using the "View container" in the object library, I converted my xib file to Storyboard and now the child view controller is added to its parent, so I don’t need to add it manually from the code using addChildViewController. and rotation methods are redirected as expected.
"Container View" mainly implements embed segue and is only supported with iOS 6.
This is an updated screenshot from my storyboard:
