how can I dismiss keyboard on Enter keypress

前端 未结 4 832
无人共我
无人共我 2021-01-15 12:28

I want to dismiss my keyboard as I press RETURN key.

I have tried by putting button in view\'s back side.

But how can I do this by pressing RETURN key?

4条回答
  •  被撕碎了的回忆
    2021-01-15 13:09

    Make sure your view controller class is a delegate for your UITextField and then use the delegate method in that class:

    #pragma mark - Delegate Methods
    - (BOOL)textFieldShouldReturn:(UITextField *)textField{
        // Dismiss the keyboard when the Return key is pressed.
        [textField resignFirstResponder];
    
        return YES;
    }
    

提交回复
热议问题