0
私はストーリーボードにボタンを作成しました。それにアクションとアウトレットを作りました。私はボタンの動作でいくつかのタスクを行います。しかし、ボタン操作は2回目からのみ実行されます。タップしたときにボタンアクションが初めて機能しない
は、ここでボタンアクションのための私のコードです:
@IBOutlet weak var sendButton: UIButton!
@IBOutlet weak var txtEmail: UITextField!
P.S.:
@IBAction func sendButtonTapped(sender: UIButton) {
let domain = String(txtEmail.text!.characters.suffix(9))
if txtEmail.text == "" || domain != "nu.edu.kz" {
let alertController = UIAlertController(title: "Error", message: "Please enter your valid nu.edu.kz e-mail", preferredStyle: .Alert)
let defaultAction = UIAlertAction(title: "Ok", style: .Cancel, handler: nil)
alertController.addAction(defaultAction)
self.presentViewController(alertController, animated: true, completion: nil)
} else {
if sendButton.currentTitle != "Reset Password has been sent" {
FIRAuth.auth()?.sendPasswordResetWithEmail(self.txtEmail.text!, completion: { (error) in
print(error?.localizedDescription)
if error != nil {
print(error?.localizedDescription)
} else {
print("reset password email has been sent")
self.sendButton.setTitle("Reset Password has been sent", forState: .Normal)
}
})
}
}
}
そして、私は私のボタンやテキストフィールドのための出口を作成している前に私が言ったように私はSwift 2.3をここで使用します。実際には、ボタンのタイトルを新しいものに設定したいと思います。そして、これは2回目のタップ後に変わります。
に明示的に呼び出し
presentViewController(alertController, animated: true, completion: nil)
ですそのために:私は新しいものにタイトルを設定したいと思います。私は私の質問を編集します –これは私のために働いた。ありがとうございました!それがどのように役立つか説明していただけますか? –