I have 3 text fields.
The first two allow entry using the standard keyboard, the last text field brings up a picker.
I'm having issues in dismissing the keyboards - so when the 3 text field is clicked, the picker appears however the keyboard from a previous text field remains on the screen.
Each of my text fields has a tag and I'm using the following code:
-(void)textFieldDidBeginEditing:(UITextField *)textField { //Keyboard becomes visible
if (textField.tag == 1) {
[_textField2 resignFirstResponder];
_myPicker.hidden = true;
}
if (textField.tag == 2) {
[_textField1 resignFirstResponder];
_myPicker.hidden = true;
}
if (textField.tag == 3) {
[_textField1 resignFirstResponder];
[_textField1 resignFirstResponder];
}
}
Any ideas on how to fix this?
Ensure the textfield's delegate is set to the class this code is in.
This can be done in Interface Builder or by using:
[_textField1 setDelegate:self];
[_textField2 setDelegate:self];
in viewDidLoad
Also ensure the class conforms to the UITextFieldDelegate protocol
You have to set the delegates for the text fields. You have to use <UITextFieldDelegate>
and self._textField1.delegate = self;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.