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
Instantiate View Controller Swift 3 Tab Bar Controller
提问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 Storyboard
set identifier to UITabbarController
and then using instantiateViewController
present 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)