我正在尝试围绕 Reactive Cocoa,一切正常,除了RAC(self.windButton.enabled)
部分(在底部),reduce 块永远不会被调用。如果有人能指出我的错误,我会很高兴。代码是不言自明的,基本上app是这样的:
这是实现
#import "ViewController.h"
@interface ViewController ()
@property (strong, nonatomic) NSNumber *winding;
@property (strong, nonatomic) NSNumber *minWinding;
@property (strong, nonatomic) NSNumber *maxWinding;
@property (weak, nonatomic) IBOutlet UIButton *windButton;
@property (weak, nonatomic) IBOutlet UIButton *unwindButton;
@property (weak, nonatomic) IBOutlet UILabel *windingLabel;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.winding = @0;
self.minWinding = @0;
self.maxWinding = @15;
RACSignal *windingSignal = RACAble(self.winding);
RACSignal *maxWindingSignal = RACAble(self.maxWinding);
RACSignal *minWindingSignal = RACAble(self.minWinding);
RAC(self.windingLabel.text) = [windingSignal map:^id(NSNumber *winding) {
return winding.stringValue;
}];
[[self.windButton rac_signalForControlEvents:UIControlEventTouchUpInside]
subscribeNext:^(id sender) {
self.winding = @(self.winding.integerValue + 1);
}];
[[self.unwindButton rac_signalForControlEvents:UIControlEventTouchUpInside]
subscribeNext:^(id sender) {
self.winding = @(self.winding.integerValue - 1);
}];
RAC(self.windButton.enabled) = [RACSignal
combineLatest:@[windingSignal, maxWindingSignal]
reduce:^(NSNumber *winding, NSNumber *maxWinding) {
return @(winding.intValue < maxWinding.intValue);
}];
RAC(self.unwindButton.enabled) = [RACSignal
combineLatest:@[windingSignal, minWindingSignal]
reduce:^(NSNumber *winding, NSNumber *minWinding) {
return @(winding.intValue > minWinding.intValue);
}];
}
我的问题是按钮永远不会被禁用。