1
votes

Hello I have tab bar controller with 5 elements. When I press the last one there are bunch of buttons which needs to show another view controller and then when I press second time to that tab bar button it needs to be revert its first condition (bunch of buttons) it is like a navigator. I tried to use following code:

let destinationVC = self.storyboard?.instantiateViewController(withIdentifier: "third") as? ThirdVC
self.tabBarController?.present(destinationVC!, animated: true, completion: nil)

However, view controller appears in a new screen and my tab bar controller is gone. How can I open my view controller above tab bar controller? Is it possible to do it ?

1
try self.tabBarController?.navigationController?.present(destinationVC!, animated: true, completion: nil) - Neel Bhasin
Nope it didn't work for me do I need to add a navigation controller inside of my tab bar? - atalayasa
either you can simply change the current vc for the tabBarcontroller tabBarController.addChildViewController(vc) - Neel Bhasin

1 Answers

4
votes

Try getting reference of the tabbar viewcontroller :

let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = mainStoryboard.instantiateViewController(withIdentifier: "tabBarcontroller") as! UITabBarController
viewcontroller.selectedIndex = indexofyourvc i.e 0,1 etc

And push with the navigation controller :

self.navController?.pushViewController(viewController, animated: true )