Reputation: 109
I want to perform an action when I click a button of a UIAlertController, I found a lot of information about this but none of them was useful for me, the closer answer I got was in this site: http://nshipster.com/uialertcontroller/
And the code I implement is this:
func success(message: String) {
let alertSuccess = UIAlertController(title: "Listo", message: message, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction (title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alertSuccess.addAction(okAction)
}
func paymentConfirmation(message: String) {
self.myAlert = UIAlertController(title: "Confirmación", message: message, preferredStyle: UIAlertControllerStyle.alert)
let myServices = UIAlertAction (title: "Si", style: UIAlertActionStyle.default) { action in
self.success(message: "Tu pago ha sido exitoso")
}
self.myAlert.addAction(myServices)
let okAction = UIAlertAction (title: "No", style: UIAlertActionStyle.cancel, handler: nil)
self.myAlert.addAction(okAction)
self.present(self.myAlert, animated: true, completion: nil)
return
}
At the paymentConfirmation function is where I have the button that I want to show a second UIALertController, the name of the button is (myServices), so I added the action I want to that button to perform and then I call the method in this block:
self.paymentConfirmation(message: "¿Estás seguro que quieres comprar el siguiente paquete de internet?")
So, what the App should do is that when the user clicks on "Si" at the first button Alert it should appear a second Alert, but this is not happening, it doens't do anything, can somebody help me?
Upvotes: 1
Views: 3567
Reputation: 20804
You are missing the second UIAlertController
presentation
func success(message: String) {
let alertSuccess = UIAlertController(title: "Listo", message: message, preferredStyle: UIAlertControllerStyle.alert)
let okAction = UIAlertAction (title: "OK", style: UIAlertActionStyle.cancel, handler: nil)
alertSuccess.addAction(okAction)
self.present(alertSuccess, animated: true, completion: nil)
}
Upvotes: 2