iOS fifth day (1: The Listener of the Cancel button and the set Agent TextField word limit)

Source: Internet
Author: User

***********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)

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.