Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable tabs in UITabBarController?

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
}
like image 922
Torewin Avatar asked Nov 01 '25 07:11

Torewin


1 Answers

Try this:

let arrayOfTabBarItems = self.tabBar.items

if let barItems = arrayOfTabBarItems, barItems.count > 0 {
  let tabBarItem = barItems[0]
  tabBarItem.isEnabled = true
}
like image 73
Wilson Avatar answered Nov 03 '25 22:11

Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!