#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...