我在iOS应用中使用Firebase通知。当我单击通知然后打开第二视图控制器但标签栏似乎没有。只有导航控制器和表格视图。
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)
答案 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()