我正在尝试通过在ViewController中调用dismissViewController
来关闭swift中的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从未被忽略。可能的问题是什么?
发布于 2014-07-10 13:35:43
我有一个解决你问题的办法。如果您使用code呈现视图,请尝试使用此代码关闭视图控制器:
Swift 3:
self.dismiss(animated: true, completion: nil)
或
如果您使用"push“segue呈现视图
self.navigationController?.popViewController(animated: true)
发布于 2014-07-10 13:49:36
如果您这样做,我猜您可能在控制台中得不到println消息,
@IBAction func cancel(sender: AnyObject) {
if(self.presentingViewController){
self.dismissViewControllerAnimated(false, completion: nil)
println("cancel")
}
}
@IBAction func done(sender: AnyObject) {
if(self.presentingViewController){
self.dismissViewControllerAnimated(false, completion: nil)
println("done")
}
}
发布于 2016-10-20 13:04:50
在Swift 3.0到4.0中,只需在函数中输入以下内容:
self.dismiss(animated: true, completion: nil)
或者,如果你在一个导航控制器中,你可以“弹出”它:
self.navigationController?.popViewController(animated: true)
https://stackoverflow.com/questions/24668818
复制相似问题