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

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
The GitHub Blog
The GitHub Blog
J
Java Code Geeks
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
A
About on SuperTechFans
博客园 - 三生石上(FineUI控件)
罗磊的独立博客
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
有赞技术团队
有赞技术团队
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Vercel News
Vercel News
腾讯CDC
博客园 - 聂微东
The Cloudflare Blog
F
Fortinet All Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Visual Studio Blog
Last Week in AI
Last Week in AI
B
Blog

博客园 - 张永存(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];
                                }];