Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can i use notification & alert in swift?

    @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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I handle delete with notification and alert in there??

>Solution :

The problem is, you are trying to display another UIAlertController on the currently presented UIAlertController.

You are presenting your UIAlertController twice.

Remove the line present(alert, animated: true, completion: nil) under let alert = ....

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading