keyboard not responding to resignFirstResponder

前端 未结 5 721
遥遥无期
遥遥无期 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:08

    You appear to be resigning the first responder of the text field; however, this isn't necessarily the first responder, which may explain why calling it has no effect.

    Instead, you should use the endEditing category to recurse through all children of your view to resign the first responder from whichever view it is attached to:

    [self.view endEditing:YES];
    

    In any case, as you never want to show the keyboard, you can simply implement UITextFieldDelegate to override the default behaviour.

    - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
    {
        // Your popover code.
    
        return NO;
    }
    

    UITextFieldDelegate Protocol Reference.

提交回复
热议问题