本文介绍了如何在 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?
推荐答案
从你的图片看来,你似乎使用 push 来呈现 ViewController
From you image it seems like you presented the ViewController using push
dismissViewControllerAnimated
用于关闭使用模态呈现的ViewController
The dismissViewControllerAnimated
is used to close ViewControllers that presented using modal
Swift 2
navigationController.popViewControllerAnimated(true)
Swift 4
navigationController?.popViewController(animated: true)
dismiss(animated: true, completion: nil)
这篇关于如何在 Swift 中关闭 ViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!