UIVIew endEditing: YES does not hide the keyboard

I have a UIVIew which is a preview and contains several UITextFields. One of these text fields (which is intended for DATE) should not be edited using the keyboard, instead I use PopOver with a Datepicker inside.

I run the method when it is reached UIControlEventEditingDidBegin. This method calls resignFirstResponderon DateTextField.

Everything works fine, if DateTextField is the first field for editing, but when another text screen is edited and, of course, shows the keyboard and then tries to edit DateField, the keyboard does not hide, and everything goes fine, but there is something to do with the keyboard.

I tried calling the method endEditing:YESbefore resignFirstResponder, but it does not work. I tried to run endEditing:YES, and resignFirstResponderin the method of the text box didEndEditing, but this is no way to remove this keyboard.

here is my method:

- (void)showDatePopOver:(id)sender{ 
    [self.view endEditing:YES];

    UITextField *textField = (UITextField *)sender;
    [sender resignFirstResponder]; // hide keyboard

    /** POP OVER LINES**/
}
+5
source share
1 answer

You should use the delegate method textFieldShouldBeginEditing:instead of canceling the first responder in didBeginEditing:

This will allow you to edit EVERYTHING BUT the text box dateTextField:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
    return (![textField isEqual:dateTextField]);
}

You must indicate that your view controller is also a text view delegate, as well (in the interface declaration [.h file]):

@interface MyViewController : UIViewController <UITextFieldDelegate>
+2
source

All Articles