I have a problem with the iOS keyboard. I have a UITextField inside a UITableViewCell. When tapping on another TableViewCell within the same TableView, I want to dismiss the keyboard before showing a UIPopoverController. All of this is shown in a form sheet.
Here is the view hierarchy:
- Root View Controller
UINavigationController
, shown asUIModalPresentationFormSheet
- Table View Controller
- Table View Cell 1
- Text Field
- Table View Cell 2
- When tapped:
UIPopoverController
containing aUIDatePicker
- When tapped:
- Table View Cell 1
- Table View Controller
In this graph, I want to add code in tableView:didSelectRowAtIndexPath:
to dismiss the keyboard just before showing the UIPopoverController
. This is not a problem on iPhone as I use a fullscreen modal view controller instead of a popover controller.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
// nameTextField is the text field in Table View Cell 1
[nameTextField resignFirstResponder];
UITextField *tempTextField = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 100, 10)];
[self.view addSubview:tempTextField];
[self.view setNeedsDisplay];
tempTextField.enabled = NO;
[tempTextField becomeFirstResponder];
[tempTextField resignFirstResponder];
[tempTextField removeFromSuperview];
[self.view endEditing:YES];
KDDatePickerViewController *dpvc = [[KDDatePickerViewController alloc] init];
popoverController = [[UIPopoverController alloc] initWithContentViewController:dpvc];
[popoverController presentPopoverFromRect:[self.tableView cellForRowAtIndexPath:indexPath].frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
}
As you can see from the code, I tried calling resignFirstResponder
and endEditing
, and I tried to create a temporary text field.
I also tried implementing disablesAutomaticKeyboardDismissal
, but it was never called.
Can anyone see what I am doing wrong?