I want to know if there is a way to use some view controllers within a view controller which provides the same functionality as Fragment
s in Android?
I want to use custom view controllers so I do not want to use NSTabViewController
, UISplitViewController
etc.
Asked
Active
Viewed 2.6k times
33

MathMax
- 571
- 7
- 22

Sarasranglt
- 3,819
- 4
- 23
- 36
1 Answers
46
Container View Controllers
allow to include child view controller inside another view controller. Take a look at the docs by clicking on the "more..." link in the class overview.
Implementing a Container View Controller
A custom UIViewController subclass can also act as a container view controller. A container view controller manages the presentation of content of other view controllers it owns, also known as its child view controllers. A child's view can be presented as-is or in conjunction with views owned by the container view controller....
Using them in storyboards is as simple as dragging the Container View to your view controller.
And Xcode will automatically add a child view controller to it

Tomas Camin
- 9,996
- 2
- 43
- 62
-
`Container View` is not available when using Xib's though. My approach is to add a view controller in code by calling `- (void)addChildViewController:(UIViewController *)childController;` -> https://developer.apple.com/documentation/uikit/uiviewcontroller/1621394-addchildviewcontroller – Bruno Bieri Jul 10 '19 at 08:50
-
1This answer gives you also a hint: https://stackoverflow.com/a/32554359 and the Apple documentation can help you: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/ImplementingaContainerViewController.html#//apple_ref/doc/uid/TP40007457-CH11-SW13 – Bruno Bieri Jul 15 '19 at 11:16