UINavigation Controller from a ViewController



我试图在没有导航的情况下从HomeViewController推送SecondViewController作为导航。然而,在我按下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有一个导航,我创建了ViewController的扩展,以设置导航前进方向:

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转换之后没有显示导航栏。我做错了什么

最后我发现了错误。基本上我打电话给self.navigationController?.navigationBar.isHidden = false在按下SecondViewController之前,导航显示:

private func goToCentralDeNotificacoes() {
let notificationCenterVC = NotificationCentralListViewController(user: UserHelper.shared.user, notificationSpotlightId: nil)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.pushViewController(notificationCenterVC, animated: true)
}

相关内容

  • 没有找到相关文章

最新更新