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

前端 未结 12 1474
野趣味
野趣味 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:49

    Try this,

    [textField setDelegate: self];
    

    Then, in textField delegate method

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

提交回复
热议问题