ios - 如何在使用 Swift 呈现新的 Viewcontroller 后关闭以前的 Viewcontroller?

标签 ios swift xcode uiviewcontroller

我的场景,在我的项目中,我维护了三个 ViewController (Main、VC1 和 VC2)。在主要的 ViewController 中,我正在维护 UIButton,单击此按钮可显示 Model View Controller 的 VC1。同样,VC1 我正在维护 UIButton,点击操作将模型呈现给 VC2VC2 呈现后,我需要关闭 VC1。

//  presenting ViewController
var presentingViewController: UIViewController! = self.presentingViewController

self.dismissViewControllerAnimated(false) {
      // go back to MainMenuView as the eyes of the user
      presentingViewController.dismissViewControllerAnimated(false, completion: nil)
}

最佳答案

VC2 的关闭按钮操作中试试这个

var vc = self.navigationController?.presentingViewController
while vc?.presentingViewController != nil {
    vc = vc?.presentingViewController
}
vc?.dismiss(animated: true, completion: nil)

关于ios - 如何在使用 Swift 呈现新的 Viewcontroller 后关闭以前的 Viewcontroller?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56142973/

相关文章:

ios - 从后台应用程序使用 url scheme 打开应用程序

ios - UICollectionView 显示与所选单元格相关的图像

ios - 在 xcode 6 中使用 swift 的 AdMob 横幅

objective-c - cocoa 代码中的内存泄漏

xcode - Xcode 是用什么语言编写的?

xCode UIView 与 UITableView

ios - 在顶部带有标签的 UISearchBar TextField 中重新定位光标

ios - 如何在应用程序中获取 IPHONE 的 UUID?

来自 AST 上下文 :"的 Swift "error: in auto-import: failed to get module ' foo'

ios - Swift:处理 Facebook token 错误