IOS Study Notes (4) two ways to reclaim the keyboard

Source: Internet
Author: User

The content of this lecture is very simple:

1. First, create a single view application, open mainstoryboard_iphone.storyboard, and put two lable and two textfiled:

2. Start to write the code: viewcontroller. h:

#import <UIKit/UIKit.h>@interface ViewController : UIViewController{UITextField *nameField;UITextField *numberField;}@property (nonatomic,retain) IBOutlet UITextField *nameField;@property (nonatomic,retain) IBOutlet UITextField *numberField;- (IBAction)backgroundTap:(id)sender;- (IBAction)textFiledReturnEditing:(id)sender;@end

Viewcontroller. M:

# Import "viewcontroller. H "@ interface viewcontroller () @ end @ implementation viewcontroller @ synthesize namefield; @ synthesize numberfield;-(void) viewdidload {[Super viewdidload]; // do any additional setup after loading the view, typically from a nib .} -(void) viewdidunload {[Super viewdidunload]; // release any retained subviews of the main view .} // The event triggered when a blank view is clicked-(ibaction) backgroundtap :( ID) sender { [Namefield resignfirstresponder]; // The notification text loses the first responder status [numberfield resignfirstresponder];} // The event triggered when you click return-(ibaction) textfiledreturnediting :( ID) sender {[Sender resignfirstresponder];}-(bool) condition :( uiinterfaceorientation) interfaceorientation {If ([[uidevice currentdevice] userinterfaceidiom] = condition) {return (interfaceorientation! = Uiinterfaceorientationportraitupsidedown);} else {return yes; }}@ end

3. Connect the operation and output port:

Set the category of the background view to uicontrol, so that we can process the screen event and connect the touch down output of the control to the backgroundtap event, because clicking the soft keyboard triggers did end on exit, we connect the two textfiled did end on exit outputs to the textfiledreturnediting event. Of course, do not forget to connect the output of the two textfiled controls with the corresponding control interfaces of viewcontroller.

4. Run the program to see the effect:

When you click textfiled:

When you click return or the interface is blank:

Related Article

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.