我想以编程方式构建storyboard tabBarController的副本,如下所示:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "tabBarViewController")
viewControllers = tabBarController.childViewControllers
我的storyboard tabBarController包含7个标签。但上面的代码只为我提供了4个第一(在iPhone上)。如何从故事板中获取其他选项卡?
答案 0 :(得分:0)
问题是因为您使用了错误的属性来获取viewcontrollers
。您应该使用viewControllers代替childViewControllers。尝试下面的代码,它将返回viewControllers
值
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarController = storyboard.instantiateViewController(withIdentifier: "tabBarViewController") as! UITabBarController
let viewControllers = tabBarController.viewControllers;