【发布时间】:2021-08-18 08:50:54
【问题描述】:
我正在尝试将 SecondViewController 作为导航从 HomeViewController 推送,但还没有导航。但是,在我按下 SecondViewController 后,会发生转换,但没有显示导航栏。从 ViewController 作为导航执行转换的最佳方式是什么?
我在 AppDelegate 中所做的(我在 appdelegate 中所做的,因为我在处理 pushNotifications 响应)是验证当前控制器是否有导航:
extension UIApplication {
class func getTopViewController(base: UIViewController? = UIApplication.shared.keyWindow?.rootViewController) -> UIViewController? {
if let nav = base as? UINavigationController {
return getTopViewController(base: nav.visibleViewController)
} else if let tab = base as? UITabBarController, let selected = tab.selectedViewController {
return getTopViewController(base: selected)
} else if let presented = base?.presentedViewController {
return getTopViewController(base: presented)
}
return base
}
}
因此,如果导航可用,我将其返回,然后调用另一个函数:
if let _topVC = UIApplication.getTopViewController(), UserHelper.shared.user.cpf != nil{
_topVC.didAcceptPushNotification()
}
因此,由于 ViewController 有一个 Navigation,我创建了一个 ViewController 的 Extension 来设置导航前进:
extension UIViewController{
@objc func didAcceptPushNotification() {
DeepLinkManager.shared.checkDeepLink(navigationController: navigationController)
}
}
那我就说:
let notificationCenterVC = NotificationCentralListViewController(user: UserHelper.shared.user, notificationSpotlightId: nil)
self.navigationController?.pushViewController(notificationCenterVC, sender: self)
但是在 VC 转换后没有显示导航栏。我做错了什么?
【问题讨论】:
标签: swift iphone navigation uinavigationcontroller