【发布时间】:2016-03-31 07:09:01
【问题描述】:
我有这个用于验证表单的操作按钮,但我按下此按钮,会提示警报,当警报被解除(按“确定”)时,它会执行对主 VC 的 segue。按下按钮后,我想留在同一个 VC 中。:
@IBAction func loginButton(sender: AnyObject) {
if self.password.text == "" || self.email.text == "" {
self.displayAlert("Error", message: "Please insert email and password")
print("if")
}
}
func displayAlert(title: String, message: String) {
// cria a mensagem de alerta
var alert = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)
// adiciona botao a mensagem de alerta
alert.addAction((UIAlertAction(title: "Ok", style: .Default, handler: { (action) -> Void in
//o que faz quando o botao da mensagem de alerta é apertado.
self.dismissViewControllerAnimated(true, completion: nil)
})))
//apresenta a mensagem.
self.presentViewController(alert, animated: true, completion: nil)
}
任何想法我做错了什么? 附言。我检查了网点,没有任何技巧。
【问题讨论】: