简体   繁体   中英

Present Modal View Controller On Top of UINavigationController

I have my app that is below a UINavigationController and therefore below a UINavigationBar. I want to present a Modal View Controller on top of this UINavigationBar because the controller I wrote doesn't make sense if it's below it (that is, I want to hide the navigation bar when showing this view controller).

Presenting it with this code:

    ukc = [[UnlockKeyboardViewController alloc] init];
    [self presentModalViewController:ukc animated:NO];

Cause the Modal view controller to be below the UINavigationBar. That UINavigationBar shouldn't show up when I show this modal view. How can I go around that?

PS: This is a jailbreak app, so there's no Interface Builder.

[self.navigationController presentModalViewController:ukc animated:NO];

Extra info upon working with a related issue:

note173's answer works with animated:YES too. The user will see ukc 's view slide up over the nav stack.

And if you subsequently need to dismiss ukc and return to self 's view, do this:

        [self.navigationController dismissModalViewControllerAnimated:NO];
        [self.navigationController dismissModalViewControllerAnimated:YES]; 

The first call dismisses ukc . The second call dismisses the nav controller. What the user sees is ukc 's view sliding down to reveal self 's view, with a glimpse of the navigation stack behind it.

So what you have here is a way of switching directly from the nav stack to some other regular view controller, and then back to a base view controller, all with animations that make sequential sense.

(If your aim was to switch back and forth between the nav stack and ukc , you would dismiss ukc with one call -- self.navigationController dismissModalViewControllerAnimated:YES]; which would slide ukc 's view down to reveal the nav stack.)

Note that these methods are deprecated in iOS 5. I assume presentViewController and dismissViewControllerAnimated would do the same thing, but I haven't tested them.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM