简体   繁体   中英

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 ?

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 )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM