以UIButton的点击事件为例,可以代替add target/action for particular event事件
// 只要按钮产生这个事件,就会产生一个信号,相当于Button 的add target/action for particular event
//- (void)addTarget:(nullable id)target action:(SEL)action forControlEvents:(UIControlEvents)controlEvents;
[[_btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
//x返回的就是被监听的button对象
NSLog(@"按钮被点击%@",x);
}];
_btn.rac_command = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input) {
NSLog(@"按钮点击");
return [RACSignal empty];
}];
网友评论