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