iPad 'dismiss keyboard' button doesn't dismiss keyboard

后端 未结 3 1158
太阳男子
太阳男子 2020-12-22 12:17

I have a UITextField in a Landscape view, and when I press the \'dismiss keyboard\' button in the lower right of the UIKeyboard view, the keyboard does NOT disappear. Is the

3条回答
  •  轮回少年
    2020-12-22 12:48

    To dismiss the keyboard using the dismiss keyboard button you need to implement the delegate method

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        //Check if your text field is first responder, and if it is, have it resign
    }
    

    Alternatively, if you want to dismiss the keyboard by tapping outside of it, use

    -(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
    {
        for (UIView* view in self.view.subviews)
        {
            if ([view isKindOfClass:[UITextField class]]) {
                [view resignFirstResponder];
            }
    
            if ([view isKindOfClass:[UITextView class]]) {
                [view resignFirstResponder];
            }
        }
    }
    

提交回复
热议问题