How to hide the keyboard when I press return key in a UITextField?

前端 未结 12 1470
野趣味
野趣味 2020-12-04 07:31

Clicking in a textfield makes the keyboard appear. How do I hide it when the user presses the return key?

12条回答
  •  长情又很酷
    2020-12-04 07:55

    In viewDidLoad declare:

    [yourTextField setDelegate:self];

    Then, include the override of the delegate method:

    -(BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        [textField resignFirstResponder];
        return YES;
    }
    

提交回复
热议问题