0

I'm currently developing an iOS-App which will have 5 tabbar-icons. One of these should only be visible if you are allowed to see it. How can I hide this icon?

Abc
  • 55
  • 4

2 Answers2

1

If you want to remove the UIViewController from tabBar, add this line of code in the UITabBarControllerClass

For removal

self.viewControllers?.remove(at: tabIndex) // replace the tabIndex which you want to remove

For Add

self.viewControllers?.insert(viewController, at: tabIndex) // replace the viewcontroller with your controller and tabIndex with your index
Harsh Pipaliya
  • 2,260
  • 1
  • 14
  • 30
s4salman
  • 121
  • 6
  • 1
    I did it in a ViewController with `self.tabBarController?.viewControllers?` instead of in the UITabBarControllerClass. This did work too. – Abc May 30 '19 at 10:12
0

With the following code, you can remove the specified tab from tab bar:

let tabIndex = 3
if let tabBarController = self.tabBarController {
    if tabIndex < tabBarController.viewControllers?.count {
        var allViewControllers = tabBarController.viewControllers
        allViewControllers?.remove(at: tabIndex)
        tabBarController.viewControllers = allViewControllers
    }
}
Bhavik Modi
  • 1,517
  • 14
  • 29