I am new to ReactiveCocoa, but I find this to be a very nice and outstanding technique to reduce code complexity. I just started to test the framework, and at the moment I’m not clear, so excuse me if my problem can be solved in some obvious way.
In my application, I have a login controller with a simple form containing two text fields (username and password) and a button. I would like the button to be disabled if either of the two text fields is empty. So, I wrote this code:
RAC(self.loginButton, enabled) =
[RACSignal combineLatest:@[self.userTextField.rac_textSignal,
self.passwordTextField.rac_textSignal]
reduce:^(NSString *username,
NSString *password) {
BOOL valid = (username.length > 0 && password.length > 0);
return @(valid);
}];
It is very simple and works. The problem is that one of my text fields (password fields) has secureTextEntryand clearsOnBeginEditingthe properties set to YES. I will try to explain the undesirable behavior that I experience in this configuration:
Assume that the username and password fields are NOT empty. In this case, the button is turned on. When a user enters a password in the password field, he becomes the first responder (the keyboard appears and the user can enter his password), but due to the fact that clearsOnBeginEditingYES is set for this field, the previously entered password is cleared of the text field. Thus, the password field is now empty. The problem is that the signal is not sent, so the button remains on, even though the password field is empty.
(, , ) , isFirstResponder . , , , , , . , , , ReactiveCocoa. isFirstResponder, . , , , .
: isFirstResponder ReactiveCocoa?
: , clearsOnBeginEditing YES?
UPDATE:
, UIControlEventEditingDidBegin, isFirstResponder:
[self.passwordTextField rac_signalForControlEvents:UIControlEventEditingDidBegin]
, . , , , , , . , , , , , , .