I have a simple app to test push notifications of a rest api. I would like to show the Navigation Bars in the App but it is not working. In my AppDelegate I have the following code:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
self.registerForPushNotifications()
let url = "dev"
UserDefaults.standard.setValue(FFHelper.url(slug: url.slug()), forKey: "api-url")
var vcString = "loginView"
if KeychainSwift().get("auth-token") != nil {
vcString = "notificationsTable"
}
let initialVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: vcString)
initialVC.navigationController?.navigationBar.isHidden = false
initialVC.navigationController?.setNavigationBarHidden(false, animated: true)
window?.rootViewController = initialVC
window?.makeKeyAndVisible()
return true
}
In the Storyboard the navigation bar is enabled also:
Lastly, in the viewController, I do the same thing:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationController?.navigationBar.isHidden = false
super.viewWillAppear(animated)
}
But still after launching the app, the navigation bar ist not showing:
Can someone please tell me why this is?
You are showing vcString is your
LoginVC
,you need to use NavigationController identifier like
loginView
orYou need to embded in
NavigationControler
before showand