keyboard not responding to resignFirstResponder

前端 未结 5 767
遥遥无期
遥遥无期 2021-01-07 00:39

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 wor

5条回答
  •  灰色年华
    2021-01-07 01:18

    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.

提交回复
热议问题