【发布时间】:2020-01-05 10:31:27
【问题描述】:
我想在响应远程通知操作时显示NewMapViewController,但如果我直接实例化NewMapViewController,我会松开导航栏。如果我改为实例化 navigationController 并执行 segue,我会看到所有视图控制器(启动和登录)一个接一个地出现,这非常令人不快。有没有办法将导航栏保持在NewMapViewController 并避免级联显示所有视图控制器?一如既往,非常感谢您的帮助。
这是我尝试过的:
case Id.checkActionIdentifier:
print("Check tapped")
let userInfo = response.notification.request.content.userInfo
if let routeToCheck = userInfo[NSLocalizedString("Route", comment: "")] as? String {
RoutesArray.routeName = routeToCheck
// print("rotta is: \(routeToCheck)")
}
// let content = response.notification.request.content
// print(" Body \(content.body)")
// print(" Title \(content.title)")
NewMapViewController.routeCheckCounter = 1
// Goes to NewMapViewController but showing the splash and login VC first
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let initialViewController : UINavigationController = storyboard.instantiateViewController(withIdentifier: "MainNavigationController") as! UINavigationController
self.window?.rootViewController = initialViewController
self.window?.makeKeyAndVisible()
let vc = initialViewController.viewControllers[0]
vc.performSegue(withIdentifier: "alertToMapSegue", sender: nil)
// goes straight to NewMapViewController but looses nav bar
// let storyboard = UIStoryboard(name: "Main", bundle: nil)
// let initialViewController : UIViewController = storyboard.instantiateViewController(withIdentifier: "NewMapViewController") as! NewMapViewController
// self.window?.rootViewController = initialViewController
// self.window?.makeKeyAndVisible()
更新:
我已经能够避免通过登录vc,但仍然显示NewMapViewController之前的启动画面,代码:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "NewMapViewController") as UIViewController
self.window?.rootViewController?.show(vc, sender: self)
【问题讨论】:
标签: ios swift uinavigationcontroller