derdida derdida - 2 months ago 41
Swift Question

Add UINavigationController to UIView?

I would like to load an UINavigationController inside an UIView (SideView) - do i need a ContainerView?

Ill tried with:

let sideRoot = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("sideRoot") as! SideRootViewController
let navController = UINavigationController(rootViewController: sideRoot)
sideView.addSubview(navController.view) // sideView is a UIView


But ill only see the NavigationBar, but no content.

Do i need an ContainerView? Or is it possible to add a (non fullscreen) UINavigationController?

Answer

To Add NavigationController inside your ViewControllers custom View. You must have set thing according to that. Try this code.

let sideRoot = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("sideRoot") as! SideRootViewController
let navController = UINavigationController(rootViewController: sideRoot)
self.addChildViewController(navController)
sideView.addSuview(navController.view)