Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 在TabBarController中打开ViewController处理推送通知_Ios_Swift_Push Notification_Uitabbarcontroller_Onesignal - Fatal编程技术网

Ios 在TabBarController中打开ViewController处理推送通知

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,只有几个选项卡。 在每个选项卡中都有NavigationController和ViewController,后者具有TableView和单元格。当用户按下单元格时,他会得到DetailedViewController

我想得到的是,当我的应用程序收到推送通知时,打开DetailedViewController

我在AppDelegate中使用一个信号,我的didFinishLaunchingWithOptions看起来像(您可以看到我有一个itemID,我想传递给DetailedViewController)

  • 由于某种原因,此代码不起作用-我没有达到预期的效果 需要带ViewController的选项卡
  • 我不知道如何从TabBarController打开DetailedViewController
  • 当我最终进入DetailedViewController时-当我按下它上的“后退”按钮时会发生什么?没有包含项目列表的ViewController-在这种情况下,我将导航到哪里
  • 这段代码能很好地使用内存吗

  • 试试这个:首先实例化你的
    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作为答案,您能为案例说明正确的方法吗?