【发布时间】:2017-08-23 17:37:36
【问题描述】:
我想在单击 UIAlertController 的按钮时执行一个操作,我发现了很多关于此的信息,但没有一个对我有用,我得到的更接近的答案是在这个网站上:http://nshipster.com/uialertcontroller/
我实现的代码是这样的:
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
}
在 paymentConfirmation 函数是我想要显示第二个 UIALertController 的按钮的地方,按钮的名称是 (myServices),所以我添加了我想要该按钮执行的操作,然后我调用该方法在这个区块中:
self.paymentConfirmation(message: "¿Estás seguro que quieres comprar el siguiente paquete de internet?")
所以,应用程序应该做的是,当用户在第一个按钮 Alert 上单击“Si”时,它应该会出现第二个 Alert,但这没有发生,它什么也没做,有人可以帮助我吗?
【问题讨论】:
标签: ios swift button uialertcontroller uialertaction