3 Ways to monitor iOS text box changes

Source: Internet
Author: User
<span id="Label3"></p><p><p>declaring properties</p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">@interface logincontroler () <UITextFieldDelegate> @property (weak, nonatomic) iboutlet Uitextfield *username;@ End</pre></pre> <p><p>1, Agent Mode</p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">-(void) viewdidload{_username.delegate = self; Add Agent}-(BOOL) textField: (uitextfield *) textField shouldchangecharactersinrange: (nsrange) range Replacementstring: (    NSString *) string{NSLog (@ "%@", textfield.text);    Return true; If no is not displayed}</pre></pre> <p><p>2, Notice</p></p> <p><p>This method will need to be released after the notification, trouble, with less</p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">-(void) viewdidload{[[nsnotificationcenter defaultcenter] addobserver:self selector: @selector (textchange) name:    Uitextfieldtextdidchangenotification object:nil]; Addobserver:self Listener Object//name Listener Change Object Method//object Listen to the object nil all Listening}-(void) textchange{NSLog (@ "%@", _username.text );} -(void) dealloc{[[nsnotificationcenter defaultcenter] Removeobserver:self];//remove listener}</pre></pre> <p><p>3, Dynamic Add Execution method<br></p></p> <pre class="brush:cpp;toolbar: true; auto-links: false;"><pre class="brush:cpp;toolbar: true; auto-links: false;">-(void) viewdidload{[_username addtarget:self action: @selector (textchange) forcontrolevents:        uicontroleventeditingchanged]; forControlEvents Trigger Event}-(void) textchange{NSLog (@ "%@", _username.text);}</pre></pre> <p><p><br></p></p><p><p>3 Ways to monitor iOS text box changes</p></p></span>

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.