Here are my codes:
- (void)viewDidLoad {
[super viewDidLoad];
// passwordTextField cannot get focus after click next key due to this RAC
RAC(self.loginButton, enabled) = [RACSignal combineLatest:@[self.userTextField.rac_textSignal,
self.passwordTextField.rac_textSignal]
reduce:^id (NSString *user, NSString *password) {
if ([user length] > 0 && [password length] > 0) {
return @YES;
}
return @NO;
}];
}
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
if (textField == self.userTextField) {
[self.passwordTextField becomeFirstResponder];
} else {
[self loginAction:textField];
}
// passwordTextField cannot get focus after click next key due to returning YES
return YES;
}
- (void)loginAction:(id)sender
{
[self.userTextField resignFirstResponder];
[self.passwordTextField resignFirstResponder];
// some login actions
}
I want to move focus to passwordTextField when click return key in userTextField. But the passwordTextField get focus and then lose focus immediately. I created a subclass of UITextField
and try to find the reason. I found that if I return YES in function textFieldShouldReturn
, the passwordTextField will get a insertText
call. Then the passwordTextField will receive resignFirstResponder
call immediately. I don't know why we must return NO in function textFieldShouldReturn
now. Any one can help me?
========
Add more infomation:
I found that this issue will only appear when I user ReactiveCocoa. The version of ReactiveCocoa is 2.5.