so I have a main view controller that the view controllers will present inFront of each other and I want when user click the button in the last view controller close all of the presented modally view controllers so I used this code But I didn't get the result
let destination = matchViewController()
let appDelegate:UIApplicationDelegate = UIApplication.shared.delegate!
let initialViewController = destination
let navigationController = UINavigationController(rootViewController: initialViewController)
appDelegate.window??.rootViewController = navigationController
appDelegate.window??.makeKeyAndVisible()
I want to use unwind segue to exit But there is another problem too the last view controller will present many times in many different situations so I just to dismiss all presented modally view controllers in. this situation I rather not using the navigationController But if I had to use it pleas tell me where exactly should I use that ?
Two options:
Dismiss all view controllers on the root view controller
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
Dismiss all viewControllers until it has a presentingController
func dismissAllControllers() { guard let vc = self.presentingViewController else { return } while (vc.presentingViewController != nil) { vc.dismiss(animated: true, completion: nil) } }
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.