0

suppose I have a MainTabBarController, from one of it's tabs, I go to FirstViewController, then from FirstViewController, I go to SecondViewController (all with present modally), in SecondViewController when user hits cancel button, I want to go back to MainTabBarController, without showing FirstViewController, can I do this without NavigationController? cus I have no NavigationController in current version of my code and it will cost me many changes :(

1 Answers1

2

in your SecondViewController you can call below code on tap of cancel button, which gets the presentingViewController of SecondViewController -> presentingViewController of FirstViewController which is a TabBarController and call dismiss on it.

@objc func dismiss(_ button: UIButton) {
    self.presentingViewController?.presentingViewController?.dismiss(animated: true)
}
Suhit Patil
  • 11,748
  • 3
  • 50
  • 60