IOS hidden Keyboard.

Source: Internet
Author: User

In the view of the Uitextfield often need to enter the text after the hidden soft keyboard, to achieve a point to let the controller implementation of the view Uitextfielddelegate proxy, and then write the corresponding code.

  1. #import <UIKit/UIKit.h>
  2. @interface testveiwcontroller:uiviewcontroller<uitextfielddelegate> {
  3. Iboutlet Uitextfield *txt;
  4. }
  5. @property (Nonatomic,retain) Uitextfield *txt;
  6. @end

Then remember to specify the proxy for the text box

  1. -(void) Viewdidload {
  2. [Super Viewdidload];
  3. Txt.delegate = self;
  4. }

To hide the soft keyboard when you click Enter:

  1. -(BOOL) Textfieldshouldreturn: (Uitextfield *) TextField
  2. {
  3. [TextField Resignfirstresponder];
  4. return YES;
  5. }



Click Cancel or the deserted number to hide it. Note that there is no way to hide the return yes, I used a bit of a workaround.

  1. -(BOOL) Textfieldshouldclear: (Uitextfield *) TextField
  2. {
  3. [TextField Resignfirstresponder];
  4. Textfield.text = @ "";
  5. return NO;
  6. }

Click Other areas of the view to hide the soft keyboard.

  1. -(void) Touchesbegan: (Nsset *) touches withevent: (Uievent *) event
  2. {
  3. [txt resignfirstresponder];
  4. }

I have used my custom variables directly here.

The steps to set up the agent are important, don't forget, or you won't respond.

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.