Disable tabbar item - Swift
Here is the answer
if let arrayOfTabBarItems = tabBarViewController.tabBar.items as! AnyObject as? NSArray,tabBarItem = arrayOfTabBarItems[2] as? UITabBarItem {
tabBarItem.enabled = false
}
Here's my code for doing the same, using Swift 3:
let tabBarControllerItems = self.tabBarController?.tabBar.items
if let tabArray = tabBarControllerItems {
tabBarItem1 = tabArray[0]
tabBarItem2 = tabArray[1]
tabBarItem1.isEnabled = false
tabBarItem2.isEnabled = false
}
Just put the block of code above in the viewDidLoad()
method for starters and don't forget to create the tabBarItem
variables and you're all good to go from there!
In case someone is looking how to disable all tab bar items:
if let items = tabBarController?.tabBar.items {
items.forEach { $0.isEnabled = false }
}