12

How do I use the iOS5 ViewController containment from the Interface Builder (on the storyboard)?

The iOS documentation says this (UIViewController -> View Management -> Storyboards):

For example, you can state that one view controller’s contents are contained inside another view controller

sparkymat
  • 9,938
  • 3
  • 30
  • 48
  • 2
    You can only embed content in a `UINavigaitionController` or a `UITabBarController` in iOS 5. To embed a view controller's content in an arbitrary container view controller in a storyboard, you need to use iOS 6... – Jason Coco Jul 06 '12 at 19:46
  • How do I embed content in a UINavigationController in IB? – sparkymat Jul 06 '12 at 19:48
  • 2
    Select the controller in the storyboard, then from the menu, choose _Editor->Embed In->Navigation Controller_ – Jason Coco Jul 06 '12 at 19:50
  • 4
    Related question: [Linking child view controllers to a parent view controller within storyboard](http://stackoverflow.com/q/8198698/643383) – Caleb Jul 06 '12 at 20:11

2 Answers2

0

In Xcode 11.7 from the Interface Builder (a.k.a. Storyboard editor):

  1. Hold Ctrl and Click (i.e. macOS version of right-click) on your destination Controller (which you want to embed in some other Controller).
  2. In the popup-menu, from Presenting Segues section, drag the circle in front of Embed option, to your Source Controller.
  3. At last, another popup-menu will appear, there select viewDidLoad option (if there are multiple options).
Top-Master
  • 7,611
  • 5
  • 39
  • 71
-5

A ViewController in iOS is just an object that is bound to a view. A viewcontroller in interface builder can have a million view controllers as properties, although theres not reason for that unless the view that is connected to the view controller has a million subviews and they all need their own controller.

You can NOT state that there is view controller containment in iOS. That makes no sense. Please understand that a view controller contains nothing but a view and any outlets or code that you add to it.

It can load and show another view controller. It can hold a reference to another view controller. But view controllers do not through any hierarchical means contain another view controller.

deleted_user
  • 3,817
  • 1
  • 18
  • 27
  • 2
    UIViewControllers *can* have parent/child relationships which is a hierarchical relationship. Contains may not be the precise word, but view controllers with child view controllers whose views they add to their own view hierarchy are possible, widely used and supported by UIViewController API. – Andrew Madsen Sep 07 '12 at 21:35
  • 1
    The methods on UIViewController show a hierarchy of parent/child relationships `removeFromParentViewController` and `addChildViewController` – christophercotton Jan 15 '13 at 18:51