***********the Cancel button listens and sets the agent TextField word limit uitextfielddelegate#import "HMViewController.h"@interfaceHmviewcontroller () <UITextFieldDelegate>@end@implementationHmviewcontroller/** 1> UIButton-Uicontrol 1.1 sets the state of the control to enable, disable @property (UIView ter=isenabled) BOOL enabled; Select, uncheck @property (nonatomic,getter=isselected) BOOL selected; Highlight or not highlight @property (nonatomic,getter=ishighlighted) BOOL highlighted; 1.2 Set the layout of the control contents Vertical Center Direction @property (nonatomic) uicontrolcontentverticalalignment contentverticalalignment; Horizontal Center Direction @property (nonatomic) uicontrolcontenthorizontalalignment contenthorizontalalignment; 1.3 Add/Remove Listener Method-(void) AddTarget: (ID) Target action: (SEL) Action forcontrolevents: (uicontrolevents) controlevents; -(void) Removetarget: (ID) Target action: (SEL) Action forcontrolevents: (uicontrolevents) controlevents; 2> UILabel, UIView 3> uiimageview, UIView 4> Uitextfield, Uicontrol * * * Proxy design mode, the most widely used one in OC What is the use of design mode 1> proxies? * Listen to events that can't be monitored through addtarget! * Mainly used to charge between two objects, when certain events occur, to pass the message or the data 2> Proxy implementation steps (1) become the agent of (child) control, the Father (Controller) become the Son (textbox) agent (2) Compliance protocol, using smart tips, quickly write code (3) Implementing the Protocol Method */- (void) viewdidload{[Super Viewdidload]; UIButton*BTN =[UIButton Buttonwithtype:uibuttontypecontactadd]; Btn.center=Self.view.center; [Self.view ADDSUBVIEW:BTN]; //To register the Listening method with "Run Loop", when the button is clicked, "Run Loop" notifies the view controller to execute the @selector method[btn addtarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];}- (void) Click: (UIButton *) btn{NSLog (@"%s", __func__); [Btn removetarget:self Action: @selector (click:) forcontrolevents:uicontroleventtouchupinside];}#pragmaMark-Text Box proxy method/** What to do after becoming an agent and how to work 1> protocol: Pre-defined method names, each corresponding to different events, but no specific implementation*/-(BOOL) TextField: (Uitextfield *) TextField Shouldchangecharactersinrange: (nsrange) range replacementstring: ( NSString *)string{NSLog (@"%@ %@", Nsstringfromrange (range),string); //limit the length of the input intLOC =range.location; return(Loc <6); //if (Loc < 6) {//return YES;//} else {//return NO;// } //If no is returned, no characters are added to the text box//return YES;}@end
iOS fifth day (1: The Listener of the Cancel button and the set Agent TextField word limit)