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

时间:2017-09-21 19:44:22

标签: ios swift firebase swift3

我在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 个答案:

答案 0 :(得分:0)

您正在从标签栏控制器中以模态方式呈现第二个视图控制器的新实例。这可能不是你想要的。而只需在现有标签栏控制器中选择适当的(第二个)标签,请参阅Switching to a TabBar tab view programmatically?

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

答案 1 :(得分: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()