I am using below code in shouldPerformSegue. I want to stop or continue segue based on whether user selects delete or cancel.
I noticed that segue stops due to the alert. If I remove alert then segue works fine.
Is shouldPerformSegue
incorrect place to use such validation?
Thanks.
let alertController = UIAlertController(title: "Confirm Delete", message: "Are you sure?", preferredStyle: UIAlertControllerStyle.alert)
let deletelAction = UIAlertAction(title: "Delete", style: UIAlertActionStyle.destructive) { (result : UIAlertAction) -> Void in
print("Delete")
if self.selection != nil {
if self.selection!.delete() == true { //this is database call
self.success = true
} else {
self.success = false
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel) { (result : UIAlertAction) -> Void in
print("Cancelled delete")
self.success = false
}
alertController.addAction(deletelAction)
alertController.addAction(cancelAction)
self.present(alertController, animated: true, completion: nil)
return success