Disable tabbar item - Swift

Edward Hasted picture Edward Hasted · Jul 19, 2015 · Viewed 19.2k times · Source

How do I disable a particular tabbar item? Something like for the 3rd icon...

self.tabBarItem.items![2].enabled = false

There must be a way of doing such a simple task as a one liner? The above doesn't work...

Answer

Aditya Koukuntla picture Aditya Koukuntla · Jul 19, 2015

Here is the answer

if  let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray,tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
        tabBarItem.enabled = false
    }