4

Before I updated to Swift 3, this worked perfectly (besides isEnabled was just enabled). This code is in my UITabBarController ViewDidLoad function. The if is never met so therefore the items are never set to 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
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Torewin
  • 887
  • 8
  • 22

1 Answers1

12

Try this:

let arrayOfTabBarItems = self.tabBar.items

if let barItems = arrayOfTabBarItems, barItems.count > 0 {
  let tabBarItem = barItems[0]
  tabBarItem.isEnabled = true
}
Wilson
  • 9,006
  • 3
  • 42
  • 46