我想通过代码从viewController跳转到与Tab Bar Controller相关的第一个viewController。
tabBarController场景具有故事板标识tabView
。
我正在以这种方式工作:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc: UITabBarController!
storyboard.instantiateViewController(withIdentifier: "tabView")
vc=storyboard.instantiateViewController(withIdentifier: "tabView") as! UITabBarController
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
self.present(vc as! UIViewController, animated: true, completion: nil)
}
但是它只加载第一个viewController(满分为5)而没有相关的标签栏。我该如何解决?
答案 0 :(得分:1)
哦,这段代码看起来很错误。
工作代码:
let vc = storyboard.instantiateViewController(withIdentifier: "tabView") as! UITabBarController
self.present(vc, animated: true)
答案 1 :(得分:0)
使用
(1)如果您想从Appdelegate
let appDelegate = UIApplication.sharedApplication.delegate as! AppDelegate
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let tabBar = mainStoryboard.instantiateViewControllerWithIdentifier("TabBarController") as! TabBarController
appDelegate.window?.rootViewController = tabBar
appDelegate.window?.makeKeyAndVisible()
(2)如果您想从具有导航根的viewcontroller
导航
self.navigationController?.pushViewController(tabBar, animated: true)