我有一个简单的应用程序来测试rest api的推送通知。我想在应用程序中显示导航栏但它不起作用。在我的AppDelegate中,我有以下代码:
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
}
在故事板中,还启用了导航栏: 最后,在viewController中,我做了同样的事情:
override func viewWillAppear(_ animated: Bool) {
self.navigationController?.setNavigationBarHidden(false, animated: animated)
self.navigationController?.navigationBar.isHidden = false
super.viewWillAppear(animated)
}
答案 0 :(得分:4)
您正在显示vcString是您的LoginVC
,
您需要使用像loginView
或
您必须在展示
之前嵌入NavigationControler
let initialVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: vcString)
let navi = UINavigationController.init(rootViewController: initialVC)
和
window?.rootViewController = navi