这里有涉及到强引用的问题,具体请观看3-4 登陆验证码发送的练习视频内容
#import "ViewController.h"
#import <ReactiveObjC.h>
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIButton *reSendBtn;
/** */
@property(assign,nonatomic)int time;
/** */
@property(nonatomic,strong)RACDisposable * disposable;
/** */
@property(nonatomic,strong)RACSignal * signal;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
}
//发送验证码按钮点击
- (IBAction)reSendClick:(id)sender {
//改变按钮状态
self.reSendBtn.enabled = NO;
//设置倒计时
self.time = 10;
//每一秒进来
self.signal = [RACSignal interval:1.0 onScheduler:[RACScheduler mainThreadScheduler]];
self.disposable = [self.signal subscribeNext:^(NSDate * _Nullable x) {
NSLog(@"%@",self);
//时间先减少!
_time--;
//设置文字
NSString * btnText = _time > 0 ? [NSString stringWithFormat:@"请等待%d秒",_time]
: @"重新发送";
[self.reSendBtn setTitle:btnText forState:_time > 0?(UIControlStateDisabled):(UIControlStateNormal)];
//设置按钮
if(_time > 0){
_reSendBtn.enabled = NO;
}else{
_reSendBtn.enabled = YES;
//取消订阅!!
[_disposable dispose];
}
}];
}
-(void)dealloc{
NSLog(@"来了");
}
-(void)timerDemo{
//RAC tiemr 让你上瘾!!
[[RACSignal interval:1.0 onScheduler:[RACScheduler scheduler]] subscribeNext:^(NSDate * _Nullable x) {
NSLog(@"%@",[NSThread currentThread]);
}];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end
#import <UIKit/UIKit.h>
@interface HKViewController : UIViewController
@end
#import "HKViewController.h"
@interface HKViewController ()
@end
@implementation HKViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}