iOS Learning: Hiding keyboard methods

Source: Internet
Author: User

1, click the other blank areas of the interface to hide

Since Uiviewcontroller is inherited from Uiresponder, it is possible to overwrite-(void) Touchesbegan: (nsset *) touches withevent: (uievent *) event; This starts the touch method to cancel the first responder, The code is as follows:
[CPP]View Plaincopy
    1. When you click outside the edit box, hide the keyboard
    2. -(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
    3. {
    4. [[Self.viewviewWithTag:TAG_WORD] resignfirstresponder];
    5. [[Self.viewviewWithTag:TAG_PROVINCE] resignfirstresponder];
    6. }



2. When you click Return or done on the keyboard, hide the keyboardThis method is Uitextfield implemented delegate, when the return button on the keyboard is clicked, the -(BOOL) Textfieldshouldreturn in delegate is called: ( Uitextfield *) TextField method.
Code: [CPP]View Plaincopy
      1. Hide the keyboard when you click Return or done on the keyboard
      2. -(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
      3. {
      4. [TextField Resignfirstresponder];
      5. }

iOS Learning: Hiding keyboard methods

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.