我想向用户展示一个简单的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)
,但那也不起作用。