所以我有一个主视图 Controller , View Controller 将在彼此的前面显示,我希望当用户单击最后一个 View Controller 中的按钮时关闭所有呈现的模态视图 Controller ,所以我使用了这段代码但我没有得到结果
let destination = matchViewController()
let appDelegate:UIApplicationDelegate = UIApplication.shared.delegate!
let initialViewController = destination
let navigationController = UINavigationController(rootViewController: initialViewController)
appDelegate.window??.rootViewController = navigationController
appDelegate.window??.makeKeyAndVisible()
我想用 unwind segue 退出 但是还有一个问题 最后一个 View Controller 将在许多不同的情况下出现多次,所以我只是关闭所有呈现的模态视图 Controller 。这种情况 我宁愿不使用 navigationController 但如果我必须使用它,请告诉我我应该在哪里使用它?
最佳答案
两种选择:
关闭 Root View Controller 上的所有 View Controller
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
关闭所有 viewController,直到它有一个
presentingController
func dismissAllControllers() { guard let vc = self.presentingViewController else { return } while (vc.presentingViewController != nil) { vc.dismiss(animated: true, completion: nil) } }
关于ios - 如何关闭所有以模态方式呈现在彼此面前的 View Controller ,并 swift 展开 segue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53975698/