Add UINavigationController inside UIViewController

前端 未结 2 967
旧巷少年郎
旧巷少年郎 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 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.

提交回复
热议问题