Presenting modal view occasionally hides the navigation bar

后端 未结 4 1692
夕颜
夕颜 2021-01-01 17:48

I\'ve come across this twice now.

Sometimes using the following line of code:

[self.navigationController presentModalViewController:aViewControll         


        
相关标签:
4条回答
  • 2021-01-01 18:08

    @HeatMiser shows a great way to get around the "bug" surrounding the inability to display items on the nav bar. I'm not sure, however, if this is strictly a bug in Presentation, since modal operations ought to trump the underlying view's interface theme. Having the modal operation's theme mimic the underlying UI theme is fine, but wrapping the true modal view with a navigation view feels wrong to me (extra view object just to get a little more behavior).

    Instead, the following worked for me and gives the same behavior as "New Message" does in the Mail program (on the iPhone).

    In IB, place a UIToolBar at the top of the modal screen (mimicking the navigation bar) with "Cancel" and "Save" UIBarButtonItem's and a Flexible Space Bar Button Item in between to get the buttons to align left and right. Then, add a UILabel centered over the UIToolBar (The Font Helvetica, Bold, Size 18 appears to match the Navigation Bar Title). Connect the buttons to IBAction's on the modal's UIViewController, and you're done.

    0 讨论(0)
  • 2021-01-01 18:08

    Maybe this is obvious, but once you're done with the modal view and want to dismiss it, you should do something like this in your modal vc:

    [parentController dismissModalViewControllerAnimated:YES];

    Where parentController is a reference to the vc from where you are presenting the modal view.

    0 讨论(0)
  • 2021-01-01 18:18

    No, I ran into this as well. The problem is that when you present a modal view controller with a UIViewController based class, it does not extend the calling navigation controller's nav bar onto the modal. The modal view covers the entire screen. What I ended up doing to solve the problem was to create a UINavigationController and push the UIViewController based class onto it, and then do presentModalViewController to the navigation controller's instance.

    like:

    UIViewController *vc = [[UIViewController alloc] init];
    UINavigationController *cntrol = [[UINavigationController alloc] initWithRootViewController:vc];
    [self presentModalViewController:cntrol animated:YES];
    [cntrol release];
    

    That allowed me to have a nav bar at the top.

    I am not sure if that will help in your particular case, the only other thing I would suggest is to replicate the behavior of the modal with a UIAnimation that stops 44px below the top of the phone. That would keep the original navigation bar visible.

    0 讨论(0)
  • 2021-01-01 18:29

    If there is a navigation controller active, then you should just use

    [self.navigationController pushViewControllerAnimated:how];

    to slide another view controller in, while giving yourself and the user into a consistent user interface complete with 'automatic' back button support.

    Once a navigation controller is in use, presenting a modal view controller should only be done to enlarge the usable area on the screen. And then, you should really use a fancy animation to let the user know that you are stepping away from the "task" or "steps" that the navigation controller was embodying.

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