keyboard not responding to resignFirstResponder

ios, resignfirstresponder, uitextfield

Solution

This is very easy to do, use your UITextFieldDelegate methods specifically UITextFieldShouldBeginEditing and return NO and execute the code to show the popover instead. This way the keyboard is never shown to begin with.

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
  [self.view endEditing:YES]; // added this in for case when keyboard was already on screen
  [self editStartDate:textField];
  return NO;
}

for it to work make sure you set the delegate of the textField to self (the view controller) and in your editStartDate method remove the resignFirstResponder call.

Problem

Instead of showing the keyboard I want to display a popover view when a textField is selected (my code is at the bottom). If the keyboard isn't showing then everything works great. However, if the keyboard is showing and then the textfield is selected the keyboard doesn't get dismissed, somewhere the firstResponders must be getting lost but I don't know where. Does anyone have a solution to this? My textfield: ``` self.startDateTextField = [[UITextField alloc] initWithFrame:CGRectMake(79, 148, 138, 27)]; [self.startDateTextField setBorderStyle:UITextBorderStyleRoundedRect]; [self.startDateTextField setDelegate:delegate]; [self.startDateTextField addTarget:delegate action:@selector(editStartDate:) forControlEvents:UIControlEventEditingDidBegin]; [popoverWrapper addSubview:self.startDateTextField]; ``` and in `editStartDate:` I have: ``` -(void)editStartDate:(UITextField *)textField { [textField resignFirstResponder]; DatePickerVC *datePickerVC = [[DatePickerVC alloc] init]; datePickerVC.delegate = self; self.popoverController = [[UIPopoverController alloc] initWithContentViewController:datePickerVC]; [self.popoverController setDelegate:self]; [self.popoverController presentPopoverFromRect:CGRectMake(0, 0, 5, 5) inView:textField permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES]; } ```

Original source

Related problems