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
-
1yes you can do this :DRohit– Rohit2018-12-03 08:35:08 +00:00Commented Dec 3, 2018 at 8:35
-
do you know how?user5463574– user54635742018-12-03 08:36:03 +00:00Commented Dec 3, 2018 at 8:36
-
yes you can use protocol and delegate method to achieve thisRohit– Rohit2018-12-03 08:41:12 +00:00Commented 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!user5463574– user54635742018-12-03 08:44:18 +00:00Commented Dec 3, 2018 at 8:44
-
it will directly take you to your mainViewControllerRohit– Rohit2018-12-03 08:46:02 +00:00Commented Dec 3, 2018 at 8:46
|
Show 2 more comments
1 Answer
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)
}