繁体   English   中英

如何关闭所有视图控制器,它们在swift中以unwind segue的形式在模板中相互呈现?

[英]how to close all view controllers that presented modally inFront of each other with unwind segue in swift?

所以我有一个主视图控制器,视图控制器将呈现在彼此的前面,我想当用户单击最后一个视图控制器中的按钮关闭所有呈现的模态视图控制器,所以我使用此代码但我没有得到结果

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退出但是还有另一个问题,最后一个视图控制器会在很多不同的情况下多次呈现,所以我只是解雇所有呈现的模态视图控制器。这种情况我宁愿不使用navigationController但是如果我有用它请求告诉我应该在哪里使用它?

两种选择:

  1. 关闭根视图控制器上的所有视图控制器

     self.view.window?.rootViewController?.dismiss(animated: true, completion: nil) 
  2. 全部关闭viewControllers,直到它有一个presentingController

     func dismissAllControllers() { guard let vc = self.presentingViewController else { return } while (vc.presentingViewController != nil) { vc.dismiss(animated: true, completion: nil) } } 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM