【发布时间】:2019-10-08 14:26:18
【问题描述】:
我正在使用 Xcode 11 和 Swift 5。
收到 APNS 通知后,我需要从 AppDelegate 跳转到故事板深处的视图控制器。这个 viewController (chatVC) 位于标签栏和导航控制器以及其他几个视图控制器的后面。见下图。我知道如何检查标签通知以及如何在 AppDelegate 中使用 launchOptions 来触发跳转。但是我正在为如何为最后一个视图控制器建立上下文而苦苦挣扎,以便用户可以使用后退按钮一直返回标签栏控制器。
我已经阅读了许多 SO 答案,并尝试了许多方法,但似乎没有一个在选项卡栏控制器内具有相同的导航控制器嵌入。这是我在 AppDelegate 中的代码(在阅读通知中的标签后):
if tag == "CS" {
// Set up a Chat View Controller.
if let chatVC = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: Constants.Storyboard.chatVC) as? NewChatViewController,
let tabBarVC = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: Constants.Storyboard.tabBarController) as? UITabBarController,
let csVC = UIStoryboard(name: "Main", bundle: .main).instantiateViewController(withIdentifier: Constants.Storyboard.csViewController) as? CustomerServiceViewController,
let helpVC = UIStoryboard(name:"Main", bundle: .main).instantiateViewController(withIdentifier: Constants.Storyboard.helpVC) as? HelpViewController
{
// Set the customer service document Id.
chatVC.cs = cs
// Make the tabBarVC the Root View Controller
self.window?.rootViewController = tabBarVC
self.window?.makeKeyAndVisible()
// Select the Favorites Index.
tabBarVC.selectedIndex = 0
// Push the Customer Service VC on top.
tabBarVC.show(csVC, sender: Any?.self)
// Push the Help VC on top of Customer Service VC.
csVC.show(helpVC, sender: Any?.self)
// Push the the chat detail page on top.
helpVC.show(chatVC, sender: Any?.self)
}
}
}
return true
如何跳转到 chatVC 并在其下方设置导航上下文以便可以使用后退按钮?
【问题讨论】:
标签: swift uinavigationcontroller appdelegate xcode-storyboard tabbarcontroller