I have 5 UITextFields added on a form. One of the textfileds is for entering the date of birth. So when that particular textfield is touched instead of displaying the default keyboard, datepicker needs to be displayed.
I tried the following:
- (void)textFieldDidBeginEditing:(UITextField *)textField{
[textField resignFirstResponder];
[self showDatePicker];//this is my own function to display datepicker.
}
when this function is called the datepicker is displayed, along with the date picker the default keyboard is also displayed and that hides the datepicker. I don't know how to get rid of the default keyboard, for this particular textfiled. Please help me.
Though this is an old question, I came here while I was searching for the same.
This will work for any number/nesting of views presented in the screen,
- (void) hideKeyboard: (UIView *) view {
NSArray *subviews = [view subviews];
for (UIView *subview in subviews){
if ([subview isKindOfClass:[UITextField class]]) {
[subview resignFirstResponder];
}
[self hideKeyboard: subview ];
}
}
Later I found more intuitive way to do it,
[self.view endEditing:YES];
You can handle this in -textFieldShouldBeginEditing:.
If this method returns NO, the keyboard will not be displayed.
Simply show the date picker in this method and then return NO.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With