【发布时间】:2016-03-04 22:36:16
【问题描述】:
我想向用户展示一个简单的 UIAlertController,其中一个选项触发关闭父视图控制器。这是我正在使用的代码:
let alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "Close View", style: UIAlertActionStyle.Destructive, handler: {
action in
self.dismissViewControllerAnimated(true, completion: nil)
}))
alert.addAction(UIAlertAction(title: "CANCEL", style: UIAlertActionStyle.Cancel, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
它没有任何作用。执行“关闭视图”处理程序后,显示警报的视图控制器仍然存在。
我还在 UIAlertAction 操作块中尝试了self.navigationController?.dismissViewControllerAnimated(true, completion: nil),但这也不起作用。
【问题讨论】:
标签: swift uiviewcontroller uialertcontroller