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?
I have two UITextFields (e.g. username and password) but I cannot get rid of
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
First you need to conform to the
UITextFieldDelegateProtocol in your View/ViewController’s header file like this:Then in your .m file you need to implement the following
UITextFieldDelegateprotocol method:[textField resignFirstResponder];makes sure the keyboard is dismissed.Make sure you’re setting your view/viewcontroller to be the UITextField’s delegate after you init the textfield in the .m: