zoukankan      html  css  js  c++  java
  • ReactiveCocoa 监听Enabled和添加Command出错的处理方法

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

    这样写会出错:

    //当两个输入框有值的时候,按钮才有效
    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都整合了

    所以要写为

    @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];
                                    }];
    

      

    Blog都是随笔,只当做笔记,不会有详细介绍,测试请慎重。。。
  • 相关阅读:
    反汇编角度->C++ const
    反汇编->C++虚函数深度分析
    反汇编->C++内联
    反汇编->C++引用与指针
    数据库初步认识
    数据库系统的结构抽象与演变
    Android · PendingIntent学习
    Android · ContentProvider学习
    notepad++
    MapReduce使用JobControl管理实例
  • 原文地址:https://www.cnblogs.com/JerryBaxia/p/5015452.html
Copyright © 2011-2022 走看看