ReactiveCocoa常用方法
//1 代替kvo
[[self.redView rac_valuesForKeyPath:@"frame" observer:nil] subscribeNext:^(id x) {
NSLog(@"修改了");
}];
//2 监听事件
[[self.btn rac_signalForControlEvents:(UIControlEventTouchUpInside)] subscribeNext:^(id x) {
NSLog(@"按钮被点击");
}];
//3 代替通知
[[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardDidShowNotification object:nil]subscribeNext:^(id x) {
NSLog(@"%@",x);
} ];
//4 监听文本框
[[self.textFiled rac_textSignal]subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
// 6.处理多个请求,都返回结果的时候,统一做处理.
RACSignal *request1 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//请求数据
//AFN
NSLog(@"请求热销模块");
// 发送请求1
[subscriber sendNext:@"发送请求1"];
return nil;
}];
RACSignal *request2 = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
NSLog(@"请求最新模块");
// 发送请求2
[subscriber sendNext:@"发送请求2"];
return nil;
}];
// 使用注意:几个信号,参数一的方法就几个参数,每个参数对应信号发出的数据。
[self rac_liftSelector:@selector(updateUIWithR1:r2:) withSignalsFromArray:@[request1,request2]];
// 更新UI
- (void)updateUIWithR1:(id)data r2:(id)data1
{
NSLog(@"更新UI%@ %@",data,data1);
}
//常用宏 文本框改变 label根本改变
// [self.textFiled.rac_textSignal subscribeNext:^(id x) {
// _label.text = x;
// }];
RAC(self.label,text) = self.textFiled.rac_textSignal;