3
votes

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))
4
Show us your codejanusfidel

4 Answers

4
votes

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()
0
votes

You can use a navigation controller in your flow, so when you are in ThirdViewController use this:

if let vc = self.storyboard?.instantiateViewController(withIdentifier: "second") as? SecondViewController {
    self.navigationController?.popToViewController(vc, animated: true)
}
0
votes

The below code was able to remove the tabview and take me back to the SecondViewController

self.tabBarController?.view.removeFromSuperview()
0
votes

Switching to other item on UITabBar, where 0 insert index of UTTabBar item:

self.tabBarController?.selectedIndex = 0