实例化View Controller Swift 3标签栏控制器

时间:2017-03-04 06:51:33

标签: ios swift xcode storyboard uitabbarcontroller

如何切换到标签栏控制器? Theres 2在选项卡上查看带有导航控制器和标签栏控制器上的导航控制器的控制器。

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "PendingOverviewVC") as! PendingOverViewController
let nc = UINavigationController(rootViewController: vc)
self.present(nc, animated: false, completion: nil)

谢谢

1 个答案:

答案 0 :(得分:4)

Storyboard设置标识符UITabbarController,然后使用instantiateViewController显示UITabbarController

let storyboard = UIStoryboard(name: "PendingOverview", bundle: nil)
let tabbarVC = storyboard.instantiateViewController(withIdentifier: "TabbarIdentifier") as! UITabbarController
if let vcs = tabbarVC.viewControllers, 
   let nc = vcs.first as? UINavigationController,
   let pendingOverVC = nc.topViewController as? PendingOverViewController {

      pendingOverVC.pendingResult = pendingResult
}
self.present(tabbarVC, animated: false, completion: nil)