UITextField calls resignFirstResponder to move down.

Source: Internet
Author: User

UITextField calls resignFirstResponder to move down.
Two textfields are used in a View in the project. Because only the becomeFirstResponder method is set for one TextField, TextField is moved down when resignFirstResponder is called on the hidden keyboard, when the keyboard appears, it will return to the original position. The solution is to set becomeFirstResponder for both TexfField or none. The keyboard will appear by default. To avoid some bugs, do not set them as well. Hope to help you.
How can I use UITextFieldDelegate to hide the keyboard?

Three steps are required:
1. Add the UITextFieldDelegate protocol to your controller class, for example:
@ Interface EditingPersonViewController: UIViewController
2. Add the textFieldShouldReturn Method to the implementation file as required by the Protocol, for example:
-(BOOL) textFieldShouldReturn :( UITextField *) textField {
[TextField resignFirstResponder];
Return YES ;}
3. Direct the delegate variable of the TextField control in the xib file to the Controller class that used the UITextFieldDelegate protocol before, and right-click the delegate IBOutlet variable of the TextField to the instance of the previous controller class.
You can also use code to specify the delegate variable of the relevant TextField.
-(Void) viewDidLoad {
[Super viewDidLoad];
ItemNameField. delegate = self;
PriceField. delegate = self;
} The third step is easy to ignore. Previously, because you forgot to specify the delegate variable, you can click the return key on the keyboard. The keyboard remains hidden.

What is the resignFirstResponder?

First Responder: the control that the user is currently using to interact with, that is, the First Responder keyboard.
ResignFirst Responder: "trigger keyboard hiding" or "trigger keyboard disabling ".
On the iPhone interface, after entering the content, you often need to hide the keyboard. You can use resignFirstResponder and UITextFieldDelegate to hide the keyboard. Close the keyboard by touching the screen.

Q: Is this the status of canceling the first response or becoming the first response, which is different from that of becameFirstResponder?
A: The first response is canceled.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.