1
votes

I'm hitting my head against the wall with a navBar issue. See this sample project for a better idea of what I'm trying to achieve. Basically, my app structure is like this:

NavController -root-> ViewControllerA -> button -> push -> ViewControllerB                            --> ViewControllerC
                                                              |                                      |
                                                            button -> presentModally                 |
                                                              |                                      |
                                                              V                                      |
                                                        PopoverViewController                        |
                                                              |                                      |
                                                            button -> push to the nav controller     |
                                                              |                                      |
                                                              |                                      |
                                                              ---------------------------------------

A button on the second view controller (call it B) of the nav stack will present a modal view controller with a clear background (its modal presentation style is overCurrentContext to look like a popover):

ViewControllerB

Popover

Then, a button on the popover will push a new view controller on to the nav stack (call it C):

PresentingC

[ViewControllerC

The popover is presented by B as opposed to the actual nav controller (B defines the presentation context). This so that when the popover pushes C on the stack, C doesn't just cover B, but covers the popover as well.

The problem arises when dismissing C. The nav stack pops back to B with the popover still on top (which is my intention). However, B now fills the entire frame of the nav view controller (before C was pushed, B's top was pinned to the navBar). This causes views near the top of B to be clipped by the navBar:

enter image description here

A look at the UI Inspector confirms that this is because B's view now fills the nav controller's view:

enter image description here

This was not the case before C was presented. Any ideas as to what's causing this to happen?

3
Solved by chance?Roi Mulia

3 Answers

1
votes

You are manually pushing a view controller onto the stack which doesn't have a navigation controller. A better way to do it would be to segue from view controller B to view controller C using a segue identifier. Once you setup the segue in the storyboard you will see that view controller C gets a nav bar automatically. You might want to use a delegate method from the popover view controller to B to trigger the segue.

1
votes

I had a problem very similar to this one. I was presenting a view controller using a .overCurrentContext presentation mode. When the viewController was displayed the navigation was over it!

To solve the problem I just asked to the navigation show the new view controller instead of the old viewController.

viewController.navigationController?.present(navigationController, animated: true, completion: nil)

Doing by this way the viewController will not be behind the navigation anymore. I hope it helps someone.

0
votes

swift 5

I did this way:

let vc = viewControllerToDisplay()
let navVc = UINavigationController(rootViewController: vc)

navVc.modalPresentationStyle = .overCurrentContext
navVc.modalTransitionStyle = .crossDissolve

navigationController?.present(navVc, animated: true, completion: nil)