I have a problem to close keyboard when I have more than 1 UITextField.
I have 2 TextField : TextField1
and TextField2
and I give each of them tag 1
and 2
I want to make if tag equal to 2 then it's hide the keyboard and if I touch textfield with tag equal to 1 the keyboard visible again, that's work with my code but when I turn it back the code not do like what I want, I touch TextField1
first then TextField2
the keyboard still visible and not hiding
My code is like this
func textFieldDidBeginEditing(textField: UITextField) {
if (textField.tag == 2) {
self.view.endEditing(false)
textField.resignFirstResponder()
} else {
self.view.endEditing(true)
}
}
I also try to use Events like Editing Did Begin
and Editing Changed
but can't do like what I want
Please help me how to make keyboard hide when it's is already visible