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 :(
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)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.