My app has a navigation controller. All my controllers pop and push. One controller has 12 textfields. 2 textfields invoke other controllers. This is a UIDatePicker and then with delegation methods we set the current date in this two fields.
- (IBAction) beginEditingDateStart:(id)开发者_运维问答 sender{
[sender resignFirstResponder];
[self.remedyName becomeFirstResponder];
[self.remedyName resignFirstResponder];
[self.doseName resignFirstResponder];
[self.count resignFirstResponder];
[self.dateFrom resignFirstResponder];
[self.dateTill resignFirstResponder];
[self.doseAmount resignFirstResponder];
[self.view endEditing:NO];
[self.view resignFirstResponder];
DatePickerViewController *dateView = [[DatePickerViewController alloc] initWithNibNameAndKey:@"DatePickerViewController" bundle:[NSBundle mainBundle] key:@"from"];
dateView.delegate = self;
[self.navigationController pushViewController:dateView animated:YES];
[dateView release];
The problem is when I start to edit these two fields and the keyboard is active, we go to the datepicker controller with the keyboard and it hides my datepicker. I know that this problem can be solved but I don't know how. Please help me.
This will ask each view to resign first responder.
[self.view endEditing:YES];
As this will ask each view to resign first responder all the other calls to resign first responder are redundant. They should be removed and to reduce the risk of calling something incorrectly or out or turn like
[self.remedyName becomeFirstResponder];
You can read more about it in the Apple Docs
It could be this line that's causing the trouble:
[self.remedyName becomeFirstResponder];
Otherwise you can do something like this to make sure all views have resigned first responder:
- (void)resignFirstResponderForSubviewsOfView:(UIView *)aView {
for (UIView *subview in [aView subviews]) {
if ([subview isKindOfClass:[UITextField class]] || [subview isKindOfClass:[UITextView class]])
[(id)subview resignFirstResponder];
[self resignFirstResponderForSubviewsOfView:subview];
}
}
Then call it like this from the view controller:
[self resignFirstResponderForSubviewsOfView:[self view]];
精彩评论