[英]Is there a way to find all modally presented view controllers in Xcode 11?
[英]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但是如果我有用它請求告訴我應該在哪里使用它?
兩種選擇:
關閉根視圖控制器上的所有視圖控制器
self.view.window?.rootViewController?.dismiss(animated: true, completion: nil)
全部關閉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.