【发布时间】:2017-12-26 03:07:46
【问题描述】:
我有一个关于从我的 AppDelegate 实例化特定视图控制器的快速问题。我正在构建一个简单的聊天应用程序,当用户通过远程通知打开应用程序时需要响应。我的应用程序期望的行为是,当用户点击此通知时,应用程序将打开到该特定聊天屏幕。
应用的基本流程如下:
- 最高级别的 UI 组件是 UITabBarController
- 这个标签栏里面是一个导航控制器
- 导航控制器内部是一个视图控制器(我们称之为“列表”),它列出了所有可用的聊天窗口
- 一旦用户点击我的表格视图中列出聊天的行之一,就会推送一个新的视图控制器。这个视图控制器是聊天窗口,它会自动隐藏标签栏,但保留导航控制器的后退按钮
- 当用户点击返回按钮时,它将返回到聊天列表,标签栏将重新出现
我正在使用以下代码来显示正确的聊天屏幕。我可以点击返回按钮,它会按预期返回到聊天列表。唯一的问题是导航控制器没有嵌入到选项卡控制器中。这段代码是从func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler调用的:
let mainStoryboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let initialVC : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "ChatVC") as UIViewController
let detailVC : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "ChatDetailVC") as UIViewController
let navContr = UINavigationController(rootViewController:initialVC)
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = navContr
self.window?.makeKeyAndVisible()
initialVC.navigationController?.pushViewController(detailVC, animated: true)
如何配置我的代码以使选项卡控制器成为堆栈的顶层?它在我的故事板中被标记为“TabController”。
【问题讨论】:
-
当用户点击通知时,您需要手动执行每个导航。
-
试试this
标签: ios swift cocoa-touch uikit