Bilal Salam
Bilal Salam

Reputation: 5

Nav bar disappears when navigating to a specific view

I have a UINavigationController and I push and pop views, but in some views, I want to go to specific view from the stack so I use this code. It works but the nav bar disappears.

for controller in self.navigationController!.viewControllers as Array {
        if controller.isKind(of: HomeViewController.self) {
        self.navigationController!.popToViewController(controller, animated: true)
            break
        }
    }

Upvotes: 0

Views: 79

Answers (3)

Ron Jones Jr
Ron Jones Jr

Reputation: 36

You can try to answer proposed by @ldem

However you can also try presenting the view rather than popping

so change

self.navigationController!.popToViewController(controller, animated: true)

to

self.present(controller, animated: true, completion: nil)

Upvotes: 0

ladyhawk
ladyhawk

Reputation: 1

You can programmatically show the Navigation Bar as mentioned in Idem's comment, or if you are using XCode interface builder you may also want to ensure that the Status Bar is properly defined for each View in the Simulated Metrics area of the properties for the View - this works for non-Storyboard layouts. Simulated Metrics Section of properties in XCode Interface Builder

Upvotes: 0

lajosdeme
lajosdeme

Reputation: 2407

In your HomeViewController you could try the following:

    override func viewWillAppear(_ animated: Bool) {
       super.viewWillAppear(animated)
       self.navigationController?.setNavigationBarHidden(false, animated: animated)
   }

Upvotes: 1

Related Questions