如何在Swift中关闭ViewController?

  • 问题:
  • 我试图在swift中关闭ViewController,方法是在IBAction中调用dismissViewController

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

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

    但println无法在控制台中看到消息输出。有什么问题吗?在

  • 答案:
  • 从您的图像来看,您似乎使用push呈现了ViewController

    dismissViewControllerAnimated用于关闭使用模态显示的ViewControllerAnimated

    Swift 2

    navigationController.popViewControllerAnimated(true)

    Swift 4

    navigationController?.popViewController(animated: true)

    dismiss(animated: true, completion: nil)