フォームを検証するために使用するこのアクションボタンがありますが、このボタンを押すとアラートが表示され、アラートが終了すると(「OK」を押す)、メインにセグを実行しますVC。私は、ボタンを押した後:私が間違って何をやっているSwift:予期せずセグを実行する
@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)
}
任意のアイデアを同じVCに滞在したいのですが? Ps。私はアウトレットをチェックして、彼らと一緒にトリックはありません。
ありがとうございました!それは私のために働いた。 –
あなたの歓迎です。そして正解とマークしてください – Roee84