The iPhone keyboard is software-based, rather than physical, so additional steps are required to ensure that the keyboard is disabled after the user completes the input.
1. Click the done button to close the keyboard.
When you press the "done" button, the "did end on exit" event will be triggered. we can add the keyboard closure operation in this time.
Add in header file
-(Ibaction) textfielddoneediting :( ID) sender;
Add
-(Ibaction) textfielddoneediting :( ID) sender
{
[Sender resignfirstresponder];
}
In interface builder, press command + 2 to select the did end on exit event of the text field, drag it to the file's owner icon, and select textfielddoneediting. Save, complete.
2. Close the keyboard by touching the background
This method adds an invisible button to activate the touch background event.
Add in header file
-(Ibaction) backgroundclick :( ID) sender;
Add
-(Ibaction) backgroundclick :( ID) sender {
[Namefield resignfirstresponder];
[Numberfield resignfirstresponder];
}
Drag a round rect button to the view in the interface builder library. Stretch button to fill the entire view screen. Press command + 1 to change the button type to custom. Press command + 2, drag the touch up inside event to the file's owner icon, and select backgroundclick :. Save the XIB file.