I have created a button in my storyboard. And created an action and outlet for it. I do some tasks in action of a button. But the button action is performed only from the second time.
Here's my code for the button action:
@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)
}
})
}
}
}
And as I said before I have created an outlet for my button and textfield:
@IBOutlet weak var sendButton: UIButton!
@IBOutlet weak var txtEmail: UITextField!
P.S. I use Swift 2.3 here. Actually, I want to setTitle of the button to the new one. And this changes after tapping for the second time.