atalayasa
atalayasa

Reputation: 3490

View controller inside tab bar controller

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 ?

Upvotes: 1

Views: 1550

Answers (1)

Abhishek Master
Abhishek Master

Reputation: 192

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 )

Upvotes: 4

Related Questions