Reputation: 907
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
}
Upvotes: 4
Views: 4929
Reputation: 9136
Try this:
let arrayOfTabBarItems = self.tabBar.items
if let barItems = arrayOfTabBarItems, barItems.count > 0 {
let tabBarItem = barItems[0]
tabBarItem.isEnabled = true
}
Upvotes: 12