LBMineViewController.m
3.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
//
// LBMineViewController.m
// XianYu
//
// Created by li bo on 16/5/28.
// Copyright © 2016年 li bo. All rights reserved.
//
#import "LBMineViewController.h"
#import "GLD_WeiboListController.h"
@interface LBMineViewController ()
@end
@implementation LBMineViewController
- (instancetype)initWithTitle:(NSString *)title onClick:(void (^)(void))clickHandler{
self = [super initWithTitle:title];
if (self) {
UIButton *but = [self button];
@weakify(self);
//创建命令并强引用,防止释放不生效
but.rac_command = [[RACCommand alloc]initWithSignalBlock:^RACSignal *(id input) {
!clickHandler ?: clickHandler();
@strongify(self);
GLD_WeiboListController *vc = [GLD_WeiboListController new];
//创建信号
vc.delegateSubject = [RACSubject subject];
//订阅信号
[vc.delegateSubject subscribeNext:^(id x) {
NSLog(@"delegate生效了=====%@",x);
}];
[self.navigationController pushViewController:vc animated:YES];
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
//发送
[subscriber sendNext:@"请求数据"];
//告知命令执行完毕
[subscriber sendCompleted];
return [RACDisposable disposableWithBlock:^{
NSLog(@"资源释放完毕");
}];
}];
}];
//订阅command中的信号
[but.rac_command.executionSignals subscribeNext:^(id x) {
[x subscribeNext:^(id x) {
NSLog(@"----%@\n",x);
}];
}];
//高级用法
[but.rac_command.executionSignals.switchToLatest subscribeNext:^(id x) {
NSLog(@"---%@\n",x);
}];
// [[but.rac_command.executing skip:1] subscribeNext:^(id x) {
// if ([x boolValue] == YES) {
// NSLog(@"正在执行");
// }
// else{
// NSLog(@"执行完成");
// }
// }];
[but.rac_command execute:@1];
[self.view addSubview:but];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (UIButton *)button {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 200, CGRectGetWidth([UIScreen mainScreen].bounds), 100);
button.title = @"点一下";
[button setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
return button;
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end