002 create the first ios6.0 helloword application on xcode4.5 (2)

Source: Internet
Author: User

Develop the first ios6.0 application (helloworld) in xcode4.5)Add a keyboard discard event to the text box

Step 1: Read the first part of this blog as follows:

Develop the first ios6.0 application (helloworld) in xcode4.5)

Step 2: start coding

Add the following to the viewcontroller. h file:Code

 
// Add the interface to discard the keyboard event-(ibaction) textfiledoneediting :( ID) sender;

Add the following code to the viewcontroller. M file:

 
// Add the discard keyboard event implementation-(ibaction) textfiledoneediting :( ID) sender {[Sender resignfirstresponder];}

Then add the event we wrote to the text box link.



Finally, we successfully implemented the text box to discard the keyboard event and click on the keyboard.ReturnYou can discard the keyboard.





Advanced: Click anywhere to discard Keyboard Events (note)

Step 1: start coding

Add the following code to the viewcontroller. h file:

 
// Touch the background to close the keyboard interface-(ibaction) backgroundtap :( ID) sender;

Add the following code to the viewcontroller. M file:

// Touch the background to disable the keyboard implementation-(ibaction) backgroundtap :( ID) sender {// The variable should discard the keyboard at this time, when binding, note that it is associated with the view of the Background [textfield resignfirstresponder];}

Note that when binding events, we find that the view object does not have a touch event, so we mustChange the original uiview inheritance to uicontrol.In this way, we can connect the touch event.


The connection method is the same as the above text discard keyboard, and the same method is used for connection.


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.