RAC 监听UITextFiled值变化, 动态改变Uibutton点击状态,

兼容 输入框直接输入和直接赋值。(双向绑定)

 RACSignal *phoneInputSignal= [[RACObserve(self.phoneInputView, text) merge: 
 [self.phoneInputView rac_textSignal]] map:^id _Nullable(id  _Nullable value) {
     return @([value isNotBlank]&&((NSString*)value).length==11);
 }];

  RACSignal *passwordSignal=[[RACObserve(self.passwordInputView, text) merge: [self.passwordInputView rac_textSignal]] map:^id _Nullable(NSString * _Nullable value) {
        return @([value isNotBlank]&&value.length>=6);
   }];

RACSignal *validSignal= [[RACSignal combineLatest:@[phoneInputSignal,passwordSignal]] map:^id _Nullable(RACTuple * _Nullable value) {
       RACTupleUnpack(NSNumber *phoneVlid, NSNumber *passwordValid)= value;
       return @([phoneVlid boolValue]&&[passwordValid boolValue]);
 }];
RAC(self.loginButton,enabled)= validSignal;

    

你可能感兴趣的:(RAC)