0

How to add one extra button on TabBar without a view controller because i want to handling that button click form following method ...

override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem)
    {
        if (tabBar.items?.firstIndex(of: item))! == 3{
         //button click do some thing on existing view 
        }
    }

i already add three buttons with ViewControllers with following code

 let VC = UIStoryboard.init(name: "Main", bundle: 
 Bundle.main).instantiateViewController(identifier: VCidentifier)                                                 
 VC.tabBarItem.image = UIImage(named: selectedImage)
 VC.tabBarItem.selectedImage = UIImage(named: unSelectedImage)

and then add these ViewControllers to this

viewControllers = [firstVC,secoundVC,thirdVC,fourthVC]

but i want to add forth button without a view controller ...

Wahab Khan Jadon
  • 875
  • 13
  • 21
  • 1
    From the docs: "Tab bar items are configured through their corresponding view controller. To associate a tab bar item with a view controller, create a new instance of the UITabBarItem class, configure it appropriately for the view controller, and assign it to the view controller’s tabBarItem property. If you don't provide a custom tab bar item for your view controller, the view controller creates a default item containing no image and the text from the view controller’s title property." – koen Mar 20 '20 at 13:48

1 Answers1

1

It's not possible to add tab bar button without view controller. But you can create empty view controller and use UITabBarControllerDelegate to make whatever you want when the fourth button clicked.

Mikhail
  • 4,271
  • 3
  • 27
  • 39
  • Oh man ... it means i have to do some extra work for that ... i am trying to do it by this method and stuck in another problem .. any way i posted another question regard same problem ... please answer that with some example code ... https://stackoverflow.com/questions/60787371/how-to-open-side-menu-from-tabbar – Wahab Khan Jadon Mar 21 '20 at 11:48