With the UITextFieldDelegate
, I'm disabling my UIButton
"btnSignup" based on whether 3 UITextFields
contain information or not. Currently, it works appropriately minus the fact that for the UIButton
to reactive (run through the if
statement again), I have to click off of the UITextField
. The same is true for when I've typed something and I go back to delete it. The UIButton
remains active until I click off of the UITextField
(if I click submit without clicking elsewhere, I am able to submit, which shouldn't be the case.)
class MainVC: UIViewController, UITextFieldDelegate {
@IBOutlet var receiveName: UITextField!
@IBOutlet var receiveEmail: UITextField!
@IBOutlet var receivePhone: UITextField!
@IBOutlet var btnSignup: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
self.btnSignup.enabled = false
self.btnSignup.alpha = 0.3
self.receiveName.delegate = self
self.receiveEmail.delegate = self
self.receivePhone.delegate = self
func textFieldDidBeginEditing(textField: UITextField) {
if countElements(receiveName.text) > 0 && countElements(receiveEmail.text) > 0 && countElements(receivePhone.text) > 0 {
self.btnSignup.enabled = true
self.btnSignup.alpha = 1
} else {
self.btnSignup.enabled = false
self.btnSignup.alpha = 0.3
}
}
}
I am looking for a solution that gives a more realtime effect. The function should be listening and responding if at any time the UITextField is being edited.