![](/img/trans.png)
[英]Segue from UINavigation Controller to another UINavigation controller
[英]UINavigation Controller from a ViewController
我試圖在沒有導航的情況下將 SecondViewController 作為導航從 HomeViewController 推送。 但是,在我按下 SecondViewController 之后,會發生轉換,但沒有顯示導航欄。 從 ViewController 作為導航執行轉換的最佳方法是什么?
我在 AppDelegate 中所做的(我在 appdelegate 中所做的,因為我正在處理 pushNotifications 響應)是驗證當前 Controller 是否具有導航:
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
}
}
因此,如果導航可用,我將其返回,然后我調用另一個 Function:
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 轉換后沒有顯示導航欄。 我做錯了什么?
最后我發現了錯誤。 基本上我在推送 SecondViewController 之前調用self.navigationController?.navigationBar.isHidden = false
,然后出現了導航:
private func goToCentralDeNotificacoes() {
let notificationCenterVC = NotificationCentralListViewController(user: UserHelper.shared.user, notificationSpotlightId: nil)
self.navigationController?.navigationBar.isHidden = false
self.navigationController?.pushViewController(notificationCenterVC, animated: true)
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.