presentViewController and displaying navigation bar

后端 未结 12 506
自闭症患者
自闭症患者 2020-12-07 13:27

I have a view controller hierarchy and the top-most controller is displayed as a modal and would like to know how to display the navigation bar when using

\         


        
12条回答
  •  被撕碎了的回忆
    2020-12-07 14:31

    It is true that if you present a view controller modally on the iPhone, it will always be presented full screen no matter how you present it on the top view controller of a navigation controller or any other way around. But you can always show the navigation bar with the following workaround way:

    Rather than presenting that view controller modally present a navigation controller modally with its root view controller set as the view controller you want:

    MyViewController *myViewController = [[MyViewController alloc] initWithNibName:nil bundle:nil];
    UINavigationController *navigationController = 
        [[UINavigationController alloc] initWithRootViewController:myViewController];
    
    //now present this navigation controller modally 
    [self presentViewController:navigationController
                       animated:YES
                       completion:^{
    
                            }];
    

    You should see a navigation bar when your view is presented modally.

提交回复
热议问题