简体   繁体   English

如何从情节提要中访问tabBarViewController中所有可能的视图控制器?

[英]How to access to all possible view controllers in a tabBarViewController from storyboard?

I would like to programmatically construct a replica of the storyboard tabBarController, as follows: 我想以编程方式构造情节提要tabBarController的副本,如下所示:

   let storyboard = UIStoryboard(name: "Main", bundle: nil)
   let tabBarController = storyboard.instantiateViewController(withIdentifier: "tabBarViewController")
   viewControllers = tabBarController.childViewControllers            

My storyboard tabBarController contains 7 tabs. 我的故事板tabBarController包含7个选项卡。 But the code above only provide me with the 4 firsts (on iPhone). 但是上面的代码(在iPhone上)仅为我提供了4个第一。 How can I get the others tabs from the storyboard? 如何从情节提要中获取其他选项卡?

The problem is because you are using wrong property to get viewcontrollers . 问题是因为您使用错误的属性来获取viewcontrollers You should use viewControllers instead of childViewControllers . 您应该使用viewControllers而不是childViewControllers Try the code below, it will return 7 controllers for viewControllers value 试试下面的代码,它将为viewControllers值返回7个控制器

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "tabBarViewController") as! UITabBarController
let viewControllers = tabBarController.viewControllers;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM