Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't hide keyboard in iOS

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.

like image 581
Oleg Avatar asked Jul 06 '11 13:07

Oleg


1 Answers

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

like image 50
Paul.s Avatar answered Sep 28 '22 06:09

Paul.s