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: