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 :(

7
  • 1
    yes you can do this :D Commented Dec 3, 2018 at 8:35
  • do you know how? Commented Dec 3, 2018 at 8:36
  • yes you can use protocol and delegate method to achieve this Commented Dec 3, 2018 at 8:41
  • this way it shows SecondViewController disappear, then FirstViewController disappear and this is what I don't want to happen! Commented Dec 3, 2018 at 8:44
  • it will directly take you to your mainViewController Commented Dec 3, 2018 at 8:46

1 Answer 1

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)
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.