![](/img/trans.png)
[英]UITabBarController in storyboard hides content of UITabBarItems
[英]How can I set different UITabBarItems for the same storyboard reference included twice in a UITabBarController?
我有一个包含四个视图控制器的UITabBarController
。 其中的前两个是对同一外部故事板的故事板引用:下图中的“ BookTable”。
我想为这两项设置不同的标签栏图标,但我不知道如何做。 如果未在嵌入式情节提要中设置选项卡栏项目属性,则即使我已在控制器中配置了选项卡栏,正在运行的应用程序中也没有选项卡栏。 请参见下面的情节提要和模拟器:
如果我在嵌入式情节提要板中设置了选项卡栏项目属性,则两个选项卡栏项目都相同:
如果我在代码中设置了标签栏项目属性,则不会发生任何变化:
class TabBarController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
tabBar.items![0].title = "Test Item 1"
tabBar.items![1].title = "Test Item 1"
}
}
我有办法做到这一点,还是只需要设置一个不同的选项卡栏项目就必须复制情节提要?
不幸的是,当要在标签栏控制器中重新使用视图控制器时,Interface Builder并没有提供太多的可能性。 您必须以编程方式指定UITabBarController
的视图控制器:
class TabBarController: UITabBarController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
setUp()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
setUp()
}
func setUp() {
let storyboard = UIStoryboard(name: [storyboard id], bundle: nil)
let firstBookTableVc = storyboard.instantiateViewController(withIdentifier: "BookTable")
let secondBookTableVc = storyboard.instantiateViewController(withIdentifier: "BookTable")
//configure the view controllers here...
viewControllers = [firstBookTableVc, secondBookTableVc]
tabBar.items?[0].image = [first tab bar image]
tabBar.items?[1].image = [second tab bar image]
tabBar.items?[0].title = "first title"
tabBar.items?[1].title = "second title"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.