ios - 如何在 Swift 中关闭 ViewController?

标签 ios swift xcode storyboard viewcontroller

我试图通过在 IBAction 中调用 dismissViewController 快速关闭 ViewController

  @IBAction func cancel(sender: AnyObject) {
    self.dismissViewControllerAnimated(false, completion: nil)
    println("cancel")
}

@IBAction func done(sender: AnyObject) {
    self.dismissViewControllerAnimated(false, completion: nil)
    println("done")
}

random image of a segue

我可以在控制台输出中看到 println 消息,但 ViewController 从未被关闭。可能是什么问题呢?

最佳答案

从你的图片来看,你似乎使用推送呈现了 ViewController

dismissViewControllerAnimated 用于关闭使用模态呈现的 ViewController

swift 2

navigationController.popViewControllerAnimated(true)

swift 4

navigationController?.popViewController(animated: true)

dismiss(animated: true, completion: nil)

关于ios - 如何在 Swift 中关闭 ViewController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24668818/

相关文章:

ios - 获取使用 SSZipArchive 解压缩的文件的文件名

swift - @State 与 @ObservableObject - 哪个以及何时?

ios - Swift - UITextField 以编程方式无法输入文本

ios - 在完成之前调用 Dispatch.main.asyncAfter() 会导致应用程序崩溃

xcode - Xamarin.iOS 目标 iOS 6 SDK

ios - 在 UIPageIndicator 下面添加 UIButton

ios - “NSMutableSet”不能隐式转换为 'Set<NSObject>'

ios - 应用程序从委托(delegate) View Controller 开始

ios - 如何正确从包含表情符号的 Swift 字符串中获取子字符串?

ios - Swift:是否可以获取 UIImagePickerController 使用的 UIImageView 的默认大小?