#import "ViewController.h"
#import "ReactiveCocoa.h"
#import "Masonry.h"
#import "TwoViewController.h"
#import "LZLineChartView.h"
#import "LZLineChartSubView.h"
@interface ViewController ()
@property (nonatomic,strong)UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UIButton *myButton;
@property (nonatomic,strong)UITextField *myTextView;
@property (strong, nonatomic) IBOutletCollection(UIButton) NSArray *buttons;
@end
@implementation ViewController
- (IBAction)oneClick:(id)sender {
TwoViewController *two = [self.storyboard instantiateViewControllerWithIdentifier:@"TwoViewController"];
two.delegateSignal = [RACSubject subject];
[two.delegateSignal subscribeNext:^(id x) {
}];
[self presentViewController:two animated:YES completion:nil];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
[self inintView];
//创建一个信号
RACSignal *singal = [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
NSArray *array = @[@1,@2];
//发送信号
[subscriber sendNext:array];
//如果不发送信号。最好发送信号完毕,内部销毁信号
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"信号被摧毁了");
}];
}];
//订阅信号
[singal subscribeNext:^(id x) {
NSLog(@"%@",x);
}];
//创建信号
RACSubject *subject = [RACSubject subject];
//订阅信号
[subject subscribeNext:^(id x) {
NSLog(@"订阅第一个信号");
}];
[subject subscribeNext:^(id x) {
NSLog(@"订阅第二个信号");
}];
[subject sendNext:@1];
[subject sendNext:@2];
}
- (void)inintView{
self.nameLabel = [[UILabel alloc]init];
self.myTextView = [[UITextField alloc]init];
[self.view addSubview:self.nameLabel];
[self.view addSubview:self.myTextView];
[self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).offset(100);
make.trailing.equalTo(self.view.mas_trailing).offset(-20);
make.height.mas_equalTo(40);
make.leading.equalTo(self.view.mas_leading).offset(20);
}];
[self.myTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.nameLabel.mas_bottom).offset(20);
make.trailing.equalTo(self.view.mas_trailing).offset(-20);
make.height.mas_equalTo(self.nameLabel.mas_height);
make.width.mas_equalTo(self.nameLabel.mas_width);
}];
self.nameLabel.backgroundColor = [UIColor redColor];
self.myTextView.backgroundColor =[ UIColor yellowColor];
RAC(self.nameLabel,text)= self.myTextView.rac_textSignal;
RAC(self.myButton,enabled) = [RACSignal combineLatest:@[self.myTextView.rac_textSignal] reduce:^(NSString *text){
BOOL isEnabled = text.length>0?YES:NO;
return @(isEnabled);
}];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
RAC
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 最近叶大直播写代码,我也做点小笔记。 什么是RAC? 几乎每一篇介绍RAC的文章开头都是这么一个问题。我这篇文章是...
- 读书笔记,记录下来。适用11g,12c,10g可以参考。 1)确认数据库运行在归档模式中 2)设置该实例的clus...
- 适用11g,12c,10g可以参考。 1. 从集群的任意一个实例登录,查看spfile信息 2. 重新创建新的sp...
- 文章系列《RACSignal 》《RACDisposable》《RACSubject、RACReplaySubje...