ReactiveCocoa的举例
来源:互联网 发布:网络用语打call的意思 编辑:程序博客网 时间:2024/06/03 22:01
原帖:http://www.cocoachina.com/ios/20150123/10994.html
-(void)initUI{ [self.txtUsername.rac_textSignal subscribeNext:^(id x) { //NSLog(@"%@",x); }]; RACSignal *validUsernameSignal=[self.txtUsername.rac_textSignal map:^id(NSString *text) { return @([self isValidUsername:text]); }]; RACSignal *validPasswordSignal=[self.txtPassword.rac_textSignal map:^id(NSString *text) { return @([self isValidUsername:text]); }]; RAC(self.txtUsername,backgroundColor)=[validUsernameSignal map:^id(NSNumber *usernameValid) { return [usernameValid boolValue]?[UIColor clearColor]:[UIColor yellowColor]; }]; RAC(self.txtPassword,backgroundColor)=[validPasswordSignal map:^id(NSNumber *passwordValid) { return [passwordValid boolValue]?[UIColor clearColor]:[UIColor yellowColor]; }]; RACSignal *signUpActiveSignal=[RACSignal combineLatest:@[validUsernameSignal,validPasswordSignal] reduce:^id(NSNumber *usernameValid,NSNumber *passwordValid){ return @([usernameValid boolValue]&&[passwordValid boolValue]); }]; [signUpActiveSignal subscribeNext:^(NSNumber *signupActive) { if ([signupActive boolValue]) { self.btnLogin.enabled=YES; [self.btnLogin setBackgroundColor:[UIColor redColor]]; } else { self.btnLogin.enabled=NO; [self.btnLogin setBackgroundColor:[UIColor whiteColor]]; } }]; [[[[self.btnLogin rac_signalForControlEvents:UIControlEventTouchUpInside] doNext:^(id x) { self.btnLogin.enabled=NO; } ] flattenMap:^id(id value) { return [self signInSignal]; }] subscribeNext:^(NSNumber *signIn) { self.btnLogin.enabled=YES; BOOL success=[signIn boolValue]; if (success) { [Common addAlertViewWithTitel:@"登陆成功"]; } else { [Common addAlertViewWithTitel:@"失败"]; } }] ; }-(RACSignal*)signInSignal{ return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) { [self signInWithUserName:self.txtUsername.text password:self.txtPassword.text complete:^(BOOL success) { [subscriber sendNext:@(success)]; [subscriber sendCompleted]; }]; return nil; }];}-(void)signInWithUserName:(NSString*)username password:(NSString*)password complete:(ReturnBack)completeBlock{ dispatch_time_t time=dispatch_time(DISPATCH_TIME_NOW, (int16_t)(NSEC_PER_SEC*2.0)); dispatch_after(time, dispatch_get_main_queue(), ^{ BOOL success=[username isEqualToString:@"user"]&&[password isEqualToString:@"password"]; completeBlock(success); });}-(BOOL)isValidUsername:(NSString*)text{ return text.length>3;}
0 0
- ReactiveCocoa的举例
- ReactiveCocoa的宏
- ReactiveCocoa的导入
- ReactiveCocoa的基本使用方法
- ReactiveCocoa里的宏
- ReactiveCocoa的学习笔记
- ReactiveCocoa的那些干货~
- ReactiveCocoa的学习
- 走进ReactiveCocoa的世界
- ReactiveCocoa 的使用
- 走进ReactiveCocoa的大门
- ReactiveCocoa的运用
- ReactiveCocoa的简单用法
- ReactiveCocoa 的RACMulticastConnection使用
- ReactiveCocoa
- ReactiveCocoa
- ReactiveCocoa
- ReactiveCocoa
- iOS 面试题
- POJ 1611 The Suspects 并查集
- 安卓基本控件之ProgressBar
- 欢迎使用CSDN-markdown编辑器
- 【DP】 HDOJ 4804 Campus Design
- ReactiveCocoa的举例
- Jboss5.1 安装
- iOS开发之 UITextField
- 数据结构例程——单链表应用举例
- 【Java笔记】——如何理解线程
- Codeforces Round #319 (Div. 1) div1 A B C
- android.os.NetworkOnMainThreadException错误解决办法
- C++_递归习题汇总
- Codeforces Round #319 (Div. 1) B. Invariance of Tree