[IPhone Development] how to disable the keyboard after entering

Source: Internet
Author: User
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.

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.