我想用一個觸發父視圖控制器關閉的選項向用戶展示一個簡單的UIAlertController。這裏是我使用的代碼:如何從UIAlertController的UIAlertAction處理程序中關閉UIViewController?
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)
它沒有任何作用。執行「Close View」處理程序後,呈現警報的視圖控制器仍然存在。
我也在UIAlertAction動作塊中試過self.navigationController?.dismissViewControllerAnimated(true, completion: nil)
,但那也沒有效果。