xcode 实例化视图控制器 Swift 3 标签栏控制器

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42593088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 09:49:14  来源:igfitidea点击:

Instantiate View Controller Swift 3 Tab Bar Controller

iosswiftxcodestoryboarduitabbarcontroller

提问by Denis

How can I segue to a tab bar controller? Theres 2 view controllers on tabs with navigation controllers and a navigation controller on the tab bar controller.

如何转到标签栏控制器?标签上有 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)

Thank you

谢谢

采纳答案by Nirav D

In Storyboardset identifier to UITabbarControllerand then using instantiateViewControllerpresent that UITabbarController.

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)