从 AppDelegate 导航时导航栏消失

Navigation bar disappear when navigate from AppDelegate

当用户点击通知时,我需要导航到特定的视图控制器 tray.Therefore 我需要从 AppDelegate 重定向它们 class:

这是 AppDelegate 中的代码:

if let myVc = UIStoryboard(name : "Main",bundle : nil).instantiateViewController(withIdentifier: "MyViewController")
    as? MyViewController {

         myVc.postId = Int(postId)
         if let navigationController = self.window?.rootViewController /* as? UINavigationController */{
          navigationController.show(myVc, sender: Any?.self)
         }
  }

通过使用这段代码,当我点击通知托盘时,我可以重定向到我的 MyViewController,但问题是导航栏不见了,所以应用程序就卡在那里了。

我也试过用这个,但是通过下面的代码,它不能重定向到 myPostVc:

if let navigationController = self.window?.rootViewController  as? UINavigationController {
  navigationController.pushViewController(myVc, animated: true)
}

所以我的问题是:

如何在导航栏出现在目标视图控制器上的情况下从 AppDelegate 导航到特定的视图控制器?

将 tabBar 嵌入到导航控制器中(在代码中,当您 select 一个 tabbar 并希望将其嵌入到情节提要中的导航控制器中时,嵌入是灰色的)并使用它来推送 VC

 if let navigationController = self.window?.rootViewController  as? UINavigationController {
    navigationController.pushViewController(myVc, animated: true)
 }

或者你可以这样做

if let cu = self.window?.rootViewController as? UITabBarController
 {         
       let nav: UINavigationController = UINavigationController()

        self.window?.rootViewController = nav

        let str = UIStoryboard.init(name: "Main", bundle: nil)

        let rr = str.instantiateViewController(withIdentifier: "idOFPushedVC") 

         nav.setViewControllers([cu,rr], animated: true)

  }