How do I implement a delete notification in swift? So if I have a delete button the "are you sure" notification box pops up with delete and cancel options, I thought it would be in the info.plist but haven't seen anything, can anyone help?
Asked
Active
Viewed 653 times
0
-
nothing I yet, I know how to do the delete implementation but i just have no clue how to get the notification to pop up once the button is pressed – user9134986 Dec 29 '17 at 18:43
-
3It isn't clear what you are asking. You need to explain better. I gather you have defined a push notification that tells you app to delete something? And you want to display a message to the user asking them to confirm the delete action? If so, what part of the problem are you having trouble with? – Duncan C Dec 29 '17 at 18:45
-
sorry for being unclear, i want a notification that pops up when a delete button is pressed, one of apples standard ones that says "are you sure you want to delete" with the 2 options "delete" and "cancel", i have no idea how to set up the notification. hope that is more clear – user9134986 Dec 29 '17 at 18:48
-
1Are you sure you want a notification? Don't you want some kind of modal dialog? Example: https://stackoverflow.com/questions/25511945/swift-alert-view-ios8-with-ok-and-cancel-button-which-button-tapped – ventiseis Dec 29 '17 at 19:00
-
yes thats exactly what i want, i didn't know what those were called thank you – user9134986 Dec 29 '17 at 19:07
2 Answers
0
Its easy Just link your button to you code using an IBAction
then in the function write the alert code.
So your code should like this:
class ViewController: UIViewController {
@IBAction func showAlertButtonTapped(_ sender: UIButton) {
// create the alert
let alert = UIAlertController(title: "UIAlertController", message: "Would you like to continue learning how to use iOS alerts?", preferredStyle: UIAlertControllerStyle.alert)
// add the actions (buttons)
alert.addAction(UIAlertAction(title: "Continue", style:
UIAlertActionStyle.default, handler: nil))
alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: nil))
// show the alert
self.present(alert, animated: true, completion: nil)
}
}

Hamza
- 630
- 9
- 26
0
In swift 4
@IBAction func DeleteButtonTapped(_ sender: UIButton) {
let DeleteAlert = UIAlertController(title: "Alert", message: "Request will be deleted", preferredStyle: UIAlertControllerStyle.alert)
DeleteAlert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
//Add your Action for deleting
}))
DeleteAlert.addAction(UIAlertAction(title: "Cancel",style: .cancel, handler: { (action: UIAlertAction!) in
//if anything to do after cancel clicked
}))
present(DeleteAlert, animated: true, completion: nil)
}

Fuhad saneen
- 109
- 1
- 1
- 6