2017-07-31 87 views
0

我有一个简单的应用程序来测试休息API的推送通知。我想在应用程序中显示导航栏,但它不起作用。在我的AppDelegate我有以下代码:Swift 3 - 为什么我的导航栏不显示?

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 
} 

在故事板也启用导航栏: enter image description here 最后,在的viewController,我做同样的事情:

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

但仍在启动应用程序后,导航栏ist不显示: enter image description here 有人可以告诉我为什么这是?

+1

这个故事板IDE ntifier ** var vcString =“loginView”**是为navigationController或ViewController设置的? – Surjeet

+0

我是多么愚蠢......谢谢你的提示。这已经足以指出我的愚蠢...... :) – Thomson

回答

1

你是显示vcString是你LoginVC

你需要使用NavigationController标识符像loginView

你需要演出前在NavigationControler到embded

let initialVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: vcString) 

    let navi = UINavigationController.init(rootViewController: initialVC) 

window?.rootViewController = navi