The purpose and function of the realization
- Limit the length of the user’s cell phone number to 11 digits
- When the length of the entered phone number is 11 digits, enable to get the CAPTCHA button.
Specific implementation comparison
Realization of traditional ideas
- Listens and binds the function to which the callback is made
[self.phoneNumberInput addTarget:self
action:@selector(textFieldLimit11Characters:)
forControlEvents:UIControlEventEditingChanged];
- The function that implements the callback
- (void) textFieldLimit11Characters: (textField UITextField at *) {if (textField. Text. Length > = 11) {/ / limit length of 11 textField.text = [textField.text substringToIndex:11]; / / phone number length meet 11, cancel to obtain the authentication code button to disable the self. The getCheckNumber. Enabled = YES; } else { self.getCheckNumber.enabled = NO; }}
Implemented using ReactiveCoA
/ / limit length of 11 [self. PhoneNumberInput. Rac_textSignal subscribeNext: ^ (nsstrings * number) {if (number) length > = 11) { self.phoneNumberInput.text = [number substringToIndex:11]; } }]; RAC(self, self, self, self, self, self, self); getCheckNumber.enabled) = [RACSignal combineLatest:@[self.phoneNumberInput.rac_textSignal] reduce:^(NSString *number) { return @(number.length >= 11); }];