Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation bar disappearing when pushed programmatically

I've been working on an app for a while now and it pushes a view controller from the AppDelegate. When it does the navigation bar that was previously on the view controller being pushed disappears. Right now it's a static nav bar (not part of a navigation controller), but it has been previously and still didn't work. What am I doing wrong? Is there some sort of workaround?

This is the code in the AppDelegate that I'm using to push it:

var storyboard = UIStoryboard(name: "Main", bundle: nil)
var PostView: AnyObject! = storyboard.instantiateViewControllerWithIdentifier("NewView")

var rootViewController = self.window!.rootViewController as! UINavigationController
rootViewController.pushViewController(PostView as! UIViewController, animated: true)

pushViewController is the one I'm trying to push.

like image 443
Isaac Wasserman Avatar asked May 31 '15 23:05

Isaac Wasserman


2 Answers

On the view controller that you are trying to push, on the viewDidLoad method, try to force the navigation bar to not be hidden

self.navigationController?.setNavigationBarHidden(false, animated: false)

If this helps, check the view controller on the storyboard if you're not forcing the view controller to hides the navigation bar

Hope that helps :)

like image 68
portella Avatar answered Oct 10 '22 03:10

portella


Try this:

var storyboard = UIStoryboard(name: "NewStoryBoard", bundle: nil)

let vc = storyboard.instantiateViewController(withIdentifier: "NewView") as! UIViewController

self.navigationController?.pushViewController(vc, animated: true)
like image 39
The 50 years old DOTA2 Addict Avatar answered Oct 10 '22 01:10

The 50 years old DOTA2 Addict