0
有無功能,使警報是這樣的:CompletionHandler不關閉在UIAlertController工作
var completionHandlers: [() -> Void] = []
func alert(header: String,
message: String,
okButton: String,
completionHandler: @escaping() -> Void) {
let alert: UIAlertController = UIAlertController.init(title: header,
message: message,
preferredStyle: UIAlertControllerStyle.alert)
let ok: UIAlertAction = UIAlertAction.init(title: okButton,
style: UIAlertActionStyle.default) { (_) in
alert.dismiss(animated: true, completion: {
self.completionHandlers.append(completionHandler)
})
}
alert.addAction(ok)
self.present(alert, animated: true)
}
在這裏,這個函數的用法:
self.alert(header: "Warning", message: "The date of end must be selected", okButton: "Ок", completionHandler: {
print("test")
})
所以,問題是,什麼我completionHandler劑量工作。即使測試沒有在控制檯中打印。那麼如何糾正使用閉包的處理程序?