当我使用rootViewController时,Tab Bar似乎没有

时间:2022-10-30 23:41:24

i use Firebase Notification in my iOS App. When i click the notification then opening Second View Controller but Tab Bar doesn't seem. Only Navigation Controller and Table View seems.

我在我的iOS应用程序中使用Firebase通知。当我单击通知然后打开第二视图控制器但标签栏似乎没有。仅显示导航控制器和表视图。

enter image description here

在此处输入图像描述

        let rootViewController = self.window!.rootViewController as! UITabBarController
        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let secondViewController = storyboard.instantiateViewController(withIdentifier: "SecondViewController") as! UINavigationController
        rootViewController.present(secondViewController, animated: false)

2 个解决方案

#1


0  

You are presenting a new instance of your second view controller modally from the tab bar controller. This isn't probably what you want. Instead just select proper (second) tab in your existing tab bar controller, see Switching to a TabBar tab view programmatically?

您将从选项卡栏控制器以模态方式呈现第二个视图控制器的新实例。这可能不是你想要的。而只需在现有标签栏控制器中选择适当的(第二个)选项卡,请参阅以编程方式切换到TabBar选项卡视图?

You may need to update some data in that tab or you can completely replace the controller for that tab.

您可能需要更新该选项卡中的某些数据,或者您可以完全替换该选项卡的控制器。

#2


0  

 let controller =
            self.storyboard?.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
 let secondViewController =   self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController

 controller.setViewControllers([secondViewController], animated: true)
 let del = UIApplication.shared.delegate as! AppDelegate
 del.window?.rootViewController = controller
 del.window?.makeKeyAndVisible()

#1


0  

You are presenting a new instance of your second view controller modally from the tab bar controller. This isn't probably what you want. Instead just select proper (second) tab in your existing tab bar controller, see Switching to a TabBar tab view programmatically?

您将从选项卡栏控制器以模态方式呈现第二个视图控制器的新实例。这可能不是你想要的。而只需在现有标签栏控制器中选择适当的(第二个)选项卡,请参阅以编程方式切换到TabBar选项卡视图?

You may need to update some data in that tab or you can completely replace the controller for that tab.

您可能需要更新该选项卡中的某些数据,或者您可以完全替换该选项卡的控制器。

#2


0  

 let controller =
            self.storyboard?.instantiateViewController(withIdentifier: "TabBarViewController") as! TabBarViewController
 let secondViewController =   self.storyboard?.instantiateViewController(withIdentifier: "SecondViewController") as! SecondViewController

 controller.setViewControllers([secondViewController], animated: true)
 let del = UIApplication.shared.delegate as! AppDelegate
 del.window?.rootViewController = controller
 del.window?.makeKeyAndVisible()