Presenting a Modal View Controller hides the Navigation Bar

后端 未结 9 932
灰色年华
灰色年华 2021-01-04 00:58

I have a navigation based app with a navigation bar, but there are a few instances where instead of pushing a view controller onto the stack, I need to present the view cont

相关标签:
9条回答
  • 2021-01-04 01:38

    Simply try following code it will work

    SettingsViewController *settings    =   [[SettingsViewController alloc] init];
    UINavigationController *navcont = [[UINavigationController alloc] initWithRootViewController:settings];
    [self presentModalViewController:navcont animated:YES];
    [settings release];
    [navcont release];
    

    One need to present the navigation controller in order to have navigation bar on the presented controller

    0 讨论(0)
  • 2021-01-04 01:39

    Make sure you a presenting AND dismissing the modalViewController from the UINavigationController, like so:

    // show
    [self.navigationController presentModalViewController:vc animated:YES];
    // dismiss
    [self.navigationController dismissModalViewControllerAnimated:YES];
    

    If your view controller is actually on the UINavigationController's stack then this is the correct way to handle the presentation and dismissal of the modal view controller. If your UINavigationBar is still hidden, there is something else funky going on and we would need to see your code to determine what is happening.

    Edit

    I copied your code into an app of mine and the UIImagePickerController successfully presented and dismissed and my UINavigationController's UINavigationBar was still there. I truly believe that the problem lays elsewhere in your architecture. If you upload a zip w/ an example project I will take a look.

    0 讨论(0)
  • 2021-01-04 01:40

    I think I've seen this behavior when presenting a view controller on the wrong VC. Are you calling presentModalViewController on the navigation controller or the individual VC?

    Try calling it from the navigationController if you aren't already.

    [self.navigationController presentModalViewController:myVC animated:YES];
    
    0 讨论(0)
提交回复
热议问题