如何在Swift中解除ViewController? [英] How to dismiss ViewController in Swift?

查看:314
本文介绍了如何在Swift中解除ViewController?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过在 IBAction

  @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消息,但ViewController永远不会被解雇。可能是什么问题呢?

I could see the println message in console output but ViewController never gets dismissed. What could be the problem?

推荐答案

从你的图像来看,你好像是用推送来呈现ViewController

From you image it seems like you presented the ViewController using push

你需要使用

navigationController.popViewControllerAnimated(true)

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

The dismissViewControllerAnimated is used to close ViewControllers that presented using modal

Swift 3.0更新:

navigationController?.popViewController(animated: true)

dismiss(animated: true, completion: nil)

这篇关于如何在Swift中解除ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆