Ios 在TabBarController中打开ViewController处理推送通知
我有一个TabBarController,只有几个选项卡。 在每个选项卡中都有NavigationController和ViewController,后者具有TableView和单元格。当用户按下单元格时,他会得到DetailedViewController 我想得到的是,当我的应用程序收到推送通知时,打开DetailedViewController 我在AppDelegate中使用一个信号,我的didFinishLaunchingWithOptions看起来像(您可以看到我有一个itemID,我想传递给DetailedViewController)Ios 在TabBarController中打开ViewController处理推送通知,ios,swift,push-notification,uitabbarcontroller,onesignal,Ios,Swift,Push Notification,Uitabbarcontroller,Onesignal,我有一个TabBarController,只有几个选项卡。 在每个选项卡中都有NavigationController和ViewController,后者具有TableView和单元格。当用户按下单元格时,他会得到DetailedViewController 我想得到的是,当我的应用程序收到推送通知时,打开DetailedViewController 我在AppDelegate中使用一个信号,我的didFinishLaunchingWithOptions看起来像(您可以看到我有一个itemID,
试试这个:首先实例化你的
TabBarController
let tabBarController = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
并更改您的rootViewController
let tabBarController = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
您还可以在此处自定义全局tintColor
:
self.window?.tintColor = UIColor.init(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0)
最后设置所选索引:
tabBarController.selectedIndex = 1
就是这样:它应该会起作用。让我知道它是否有效
let storyboard = UIStoryboard.init(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "MainTabBarController") as! UITabBarController
tabBarController.selectedIndex = 1
self.window = UIWindow.init(frame: UIScreen.main.bounds)
self.window?.tintColor = UIColor.init(red: 0.0, green: 0.5, blue: 0.0, alpha: 1.0)
self.window?.rootViewController = tabBarController
self.window?.makeKeyAndVisible()
是否有理由关闭
rootViewController
?为什么不简单地在上面展示你想要的标签控制器呢?这样,至少你们的“后退”按钮会起作用(一旦你们让其他一切都正常工作了),因为当应用程序运行并收到通知时——若我不关闭显示的ViewController,会发生什么?它将打开一个新的,消耗更多内存-我错了吗?只需将您的rootViewController更改为所需的视图Controller@Mannopson以NavigationController和TabBarController作为答案,您能为案例说明正确的方法吗?