Search code examples
iosuicontainerview

What are differences between stand alone view and container view?


When I want to have a subview that has it's own view controller, I can use stand alone view that defined since XCode 7 or I can use a container view. But what are differences or advantages and disadvantages of these choices? (Through search I didn't find many differences)


Solution

  • The main (and maybe only?) difference is that by using a container view you can set up the connection to the child view controller with a segue in interface builder. That means you do not have to care about the typical child view controller setup like...

    addChildViewController(someChildViewController)
    containerView.addSubview(someChildViewController.view)
    someChildViewController.didMove(toParentViewController: self)
    

    and so on...