How to dismiss a Tab Bar Controller and go back to previous view controller on click of button
ios, swift, uitabbarcontroller, uiviewcontroller
Solution
You added tabBarController in secondViewController as subView. So you need to remove that tabBarController view from super view.
For that, you need a tabBarController object.
self.tabBarController?.view.removeFromSuperview()
Problem
I am building a flow like this FirstViewController -> SecondViewController - > Tab Bar View Controller (consists of 1. ThirdViewController and 2. FourthVIewController) I am opening Tab Bar View Controller as a pop up form the SecondViewController. However, when I run (self.dismiss(animated: true, completion: nil)) on click of a button in ThirdViewController, it goes back to the FirstViewController. I want to go back to the SecondViewController Adding code. This is how I open the tab bar view controller from my SecondViewController ``` let popupVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "tabBarVC") as! UITabBarController self.addChildViewController(popupVC) popupVC.view.frame = self.view.frame self.view.addSubview(popupVC.view) popupVC.didMove(toParentViewController: self) ``` And this is how I try to close the tab bar view controller form Third View Controller ``` self.dismiss(animated: true, completion: nil)) ```