true/false
extension UIViewController {
///
func confirm(strMsg: String, strTitle: String = "", handler: Bool->Void) {
let dialog = UIAlertController(title: strTitle, message: strMsg, preferredStyle: .ActionSheet)
let act1 = UIAlertAction(title: "OK", style: .Default) { action in
handler(true)
}
let act2 = UIAlertAction(title: "", style: .Cancel) { action in
handler(false)
}
dialog.addAction(act1)
dialog.addAction(act2)
self.presentViewController(dialog, animated: true, completion: nil)
}
}
UIViewControllerextensionUIViewController
@IBAction func deleteRecord(_: AnyObject) {
//
//...
confirm("", handler: {confirmed in
if confirmed {
//
//...
} else {
//
}
})
//
}