Add UINavigationController inside UIViewController

前端 未结 2 968
旧巷少年郎
旧巷少年郎 2021-02-15 15:55

I have a UIViewController with a UIToolbar (on bottom) and I want to add a UINavigationController with UINavigationBar inside. But the UINavigationController is not displayed.

相关标签:
2条回答
  • 2021-02-15 15:59

    For swift 5

    let childNavController = UINavigationController()
    parrentVC.addChild(childNavController)
    parrentVC.view.addSubview(childNavController.view)
    //Add constraints or frame for childNavController here.
    childNavController.didMove(toParent: parrentVC)
        
    
    0 讨论(0)
  • 2021-02-15 16:24

    Adding a view controller as a child view controller isn't enough. You also need to add the navigation controller's view as a subview of the container view controller's view.

    [myNav willMoveToParentViewController:self];
    myNav.view.frame = navFrame;  //Set a frame or constraints
    [self.view addSubview:myNav.view];
    [self addChildViewController:myNav];
    [myNav didMoveToParentViewController:self];
    

    See the View Controller Programming Guide for more details.

    0 讨论(0)
提交回复
热议问题