Three ways to listen to events

Source: Internet
Author: User

Three ways to listen to events: AddTarget--for listening to some clicks, value changes and other eventsAgent--listen to some events that change control properties, such as starting, ending, selecting a row, and so onNotice: None of the above consider using notification notifications to use note: As long as the monitoring notification will remove the notification, otherwise the controller destroyed, the notification will not find the object causes the program crashes text box event listening: Textfied agent can only listen to start editing end edit, can change the text, Can not listen to change the text after the situation, the project needs to listen to the text box for input, agent and addtarget are not applicable. Three notifications from text box: Uikit_extern nsstring *const uitextfieldtextdidbegineditingnotification;
Uikit_extern nsstring *const uitextfieldtextdidendeditingnotification; Uikit_extern nsstring *const uitextfieldtextdidchangenotification; Login interface: 1. Login button only text boxes have text to click the implementation idea: The text box changes will send notification named Uitextfieldtextdidchangenotification notification. So use this notification to listen for content within two text boxes. There is content to control the Enable status code for the login button: hgloginviewcontroller.m-(void) Viewdidload {
[Super Viewdidload];
Do any additional setup after loading the view.
/* Set some properties of the text box */
Placeholder
Self.countField.placeholder = @ "Please enter account";
Empty button
Self.countField.clearButtonMode = uitextfieldviewmodewhileediting;

Self.pwdField.placeholder = @ "Please enter password";
Ciphertext display
Self.pwdField.secureTextEntry = YES;
Self.pwdField.clearButtonMode = uitextfieldviewmodewhileediting;

/* Login button Disabled */
self.loginBtn.enabled = NO;

Registering events for monitoring notifications to the system notification hubs
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (textfieldchange) name:@ " Uitextfieldtextdidchangenotification "Object:self.countField";
[[Nsnotificationcenter Defaultcenter] addobserver:self selector: @selector (textfieldchange) name:@ " Uitextfieldtextdidchangenotification "Object:self.pwdField";
}

Three ways to listen to events

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.