ReactiveCocoa 监听Enabled和添加Command出错的处理方法

当我要控制一个按钮是否有效和添加按钮事件时ide

这样写会出错:blog

//当两个输入框有值的时候,按钮才有效
RAC(self.sendBtn, enabled) = [RACSignal combineLatest: @[self.passwordOldTxt.rac_textSignal,self.passwordTxt.rac_textSignal]
                                               reduce:^id(NSString *passwordOld, NSString *password){
  return @(passwordOld.length > 0 && password.length > 0);
}];
@weakify(self);
self.sendBtn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
    @strongify(self);
    NSLog(@"self.sendBtn.rac_command TouchUpInside %@", self.title);
    return [RACSignal empty];
}];

由于ReactiveCocoa把Enabled和Command都整合了事件

因此要写为input

 

@weakify(self);
    self.sendBtn.rac_command = [[RACCommand alloc] initWithEnabled:
                                [RACSignal combineLatest: @[self.passwordOldTxt.rac_textSignal,self.passwordTxt.rac_textSignal]
                                reduce:^id(NSString *passwordOld, NSString *password){
                                    return @(passwordOld.length > 0 && password.length > 0);
                                }] signalBlock:^RACSignal *(id input) {
                                    @strongify(self);
                                    NSLog(@"self.sendBtn.rac_command TouchUpInside %@", self.title);
                                    return [RACSignal empty];
                                }];
相关文章
相关标签/搜索