First, after the input is completed, press done on the keyboard to close the keyboard.
First select TextFields in Interface Builder, then find Text Input Traits in Text Field Attributes, and select Return Key as done. OK
Define the method
Copy the codeThe code is as follows:
- (IBAction) textFieldDoneEditing:(id)sender; //Press Done key to close the keyboard
Implementation method
Copy the codeThe code is as follows:
//Close the keyboard after pressing the Done key
- (IBAction) textFieldDoneEditing:(id)sender
{
[sender resignFirstResponder];
}
Then find the event Did End On Exit, associated with textFieldDoneEditing, OK.
What should I do if it is a numeric keyboard without the done key? We close the keyboard by touching the background
Define the method
Copy the codeThe code is as follows:
- (IBAction) backgroundTap:(id)sender; //Close the keyboard by touching the background
Implementation method
Copy the codeThe code is as follows:
//Close the keyboard by touching the background
- (IBAction) backgroundTap:(id)sender
{
[nameFiled resignFirstResponder];
[numberField resignFirstResponder];
}
Then select the background Touch Down event, associate backgroundTap, OK
One thing to note about in this method is to change the UIView to UIControl.