@IBAction func tapDeleteButton(_ sender: UIButton) {
let alert = UIAlertController(title:"Are you sure?",message: "Do you really want to delete?",preferredStyle: UIAlertController.Style.alert)
let cancle = UIAlertAction(title: "Cancel", style: .default, handler: nil)
alert.addAction(cancle)
present(alert, animated: true, completion: nil)
let delete = UIAlertAction(title: "Delete", style: .destructive){(_) in
let uuidString = self.diary?.uuidString
NotificationCenter.default.post(name: NSNotification.Name("deleteDiary"), object: uuidString, userInfo: nil)
}
alert.addAction(delete)
present(alert, animated: true, completion: nil)
}
hello.
I’m studying swift while making a diary app.
But I’m stuck creating a delete button for a cell.
I get an error when I tap delete in alert.
How can I handle delete with notification and alert in there??
2
Answers
The problem is, you are trying to display another
UIAlertController
on the currently presentedUIAlertController
.You are presenting your
UIAlertController
twice.Remove the line
present(alert, animated: true, completion: nil)
underlet alert = ...
.The issue is because, You have presented the alert twice
Try this:
}