How to make return key on iPhone make keyboard disappear?

后端 未结 14 517
有刺的猬
有刺的猬 2020-12-02 07:06

I have two UITextFields (e.g. username and password) but I cannot get rid of the keyboard when pressing the return key on the keyboard. How can I do this?

14条回答
  •  借酒劲吻你
    2020-12-02 07:44

    Implement the UITextFieldDelegate method like this:

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

提交回复
热议问题