惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园_首页
大猫的无限游戏
大猫的无限游戏
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
B
Blog RSS Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Proofpoint News Feed
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
量子位
H
Hackread – Cybersecurity News, Data Breaches, AI and More
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
T
The Blog of Author Tim Ferriss
U
Unit 42
aimingoo的专栏
aimingoo的专栏
博客园 - 叶小钗
博客园 - 【当耐特】
云风的 BLOG
云风的 BLOG
博客园 - Franky
博客园 - 聂微东

博客园 - 张永存(Jerry)

POD 创建 Xcode 项目组 ReactiveCocoa RACObserve subscribeNext 时,只有值不一样时才响应 Masonry + UIView Animations 注意事项 addObserver forKeyPath options 注意事项 ios中tabbar得title和navigationbar的title如何修改 tableview 分组显示返回footerviewt和headerView的高度不能为0的问题 UITableViewCell的选中时的颜色设置 ios 枚举 位移操作 设置UIButton 字体 颜色 ios NSString format 保留小数点 float double 屏幕自动旋转和调节大小 IOS影响Animiation动画的事件 类似9patch效果的iOS图片拉伸 CocoaPods安装 Mac OS X上安装 Ruby运行环境 XMPP 连续注册出现用户限制:500错误 处理方式 ejabberd 搭配的XMPP服务器注册失败 403 处理 在framework中打包xib 【转】 XMPP ejabberd服务 Mac 安装
ReactiveCocoa 监听Enabled和添加Command出错的处理方法
张永存(Jerry) · 2015-12-03 · via 博客园 - 张永存(Jerry)

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

这样写会出错:

//当两个输入框有值的时候,按钮才有效
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];
                                }];