简体   繁体   English

如何在UITabBarController中禁用选项卡?

[英]How to disable tabs in UITabBarController?

Before I updated to Swift 3, this worked perfectly (besides isEnabled was just enabled). 在我更新到Swift 3之前,这非常有效(除了启用了isEnabled)。 This code is in my UITabBarController ViewDidLoad function. 这段代码在我的UITabBarController ViewDidLoad函数中。 The if is never met so therefore the items are never set to true. 永远不会满足if ,因此项永远不会设置为true。

How do I access the items as I want the tabs to be greyed about until a variable is selected? 我如何访问这些项目,因为我希望选项卡显示为灰色,直到选择变量为止?

if  let arrayOfTabBarItems = self.tabBar.items as AnyObject as? NSArray,let tabBarItem = arrayOfTabBarItems[1] as? UITabBarItem {
    tabBarItem.isEnabled = true
}

Try this: 尝试这个:

let arrayOfTabBarItems = self.tabBar.items

if let barItems = arrayOfTabBarItems, barItems.count > 0 {
  let tabBarItem = barItems[0]
  tabBarItem.isEnabled = true
}

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

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