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 :(
Asked
Active
Viewed 82 times
0
-
1yes you can do this :D – Wings Dec 03 '18 at 08:35
-
do you know how? – Dec 03 '18 at 08:36
-
yes you can use protocol and delegate method to achieve this – Wings Dec 03 '18 at 08:41
-
this way it shows SecondViewController disappear, then FirstViewController disappear and this is what I don't want to happen! – Dec 03 '18 at 08:44
-
it will directly take you to your mainViewController – Wings Dec 03 '18 at 08:46
-
I should dismiss my First and Second ViewController, right? or you suggest don't dismissing them and just go to MainTabBar? – Dec 03 '18 at 08:55
-
https://stackoverflow.com/questions/51281372/swift-delegate-beetween-two-vc-without-segue/51287027#51287027 take help of this answer – Wings Dec 03 '18 at 09:14
1 Answers
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