CNLiveBindingManageController.m
7.72 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
//
// CNLiveBindingManageController.m
// CNLiveNetAdd
//
// Created by CNLive-zxw on 2019/9/10.
// Copyright © 2019 cnlive. All rights reserved.
//
#import "CNLiveBindingManageController.h"
#import <Masonry/Masonry.h>
#import "CNLiveBaseKit.h"
#import "CNLiveBindingManageHeaderView.h"
#import "CNLiveBindingManageCell.h"
#import "CNLiveBindingManageModel.h"
#import "CNLiveBindingManageRequest.h"
@interface CNLiveBindingManageController ()<UITableViewDelegate, UITableViewDataSource,CNLiveBindingManageCellDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *bindingData;
@property (nonatomic, strong) NSArray *unBindingData;
@end
@implementation CNLiveBindingManageController
#pragma mark - CNLiveBindingManageCellDelegate
- (void)clickedBindingButton:(CNLiveBindingManageCell *)cell isBinding:(BOOL)isBinding{
if(isBinding){
//绑定操作
[self requestBindingManage:cell.model];
}else{
//解除绑定操作
UIAlertController *actionAlert1 = [UIAlertController alertControllerWithTitle:@"确定解除绑定?" message:nil preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:NULL];
__weak typeof(self) weakSelf = self;
UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
[strongSelf requestBindingManage:cell.model];
}];
[action1 setValue:RGBOF(0x23D41E) forKey:@"_titleTextColor"];
[action2 setValue:RGBOF(0x23D41E) forKey:@"_titleTextColor"];
[actionAlert1 addAction:action1];
[actionAlert1 addAction:action2];
[self presentViewController:actionAlert1 animated:YES completion:nil];
}
}
- (void)requestBindingManage:(CNLiveBindingManageModel *)model{
// switch (model.type) {
// case CNLiveSendAuthRespWX:
// {
// if(![WXApi isWXAppInstalled]){
// [QMUITips showWithText:@"未安装微信" inView:self.view hideAfterDelay:1.5];
// return;
// }
// }
// break;
// case CNLiveSendAuthRespQQ:
// {
// if(![TencentOAuth iphoneQQInstalled]){
// [QMUITips showWithText:@"未安装QQ" inView:self.view hideAfterDelay:1.5];
// return;
// }
// }
// break;
// case CNLiveSendAuthRespWB:
// {
// if(![WeiboSDK isWeiboAppInstalled]){
// [QMUITips showWithText:@"未安装微博" inView:self.view hideAfterDelay:1.5];
// return;
// }
// }
// break;
// case CNLiveSendAuthRespApple:
// {
// }
// break;
// }
__weak typeof(self) weakSelf = self;
[CNLiveBindingManageRequest requestModel:model block:^(BOOL isSuccess, CNLiveBindingManageModel * _Nullable model, BOOL isBinding) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
if(isSuccess){
[strongSelf loadData];
}
}];
}
#pragma mark - Data
- (void)loadData{
__weak typeof(self) weakSelf = self;
[CNLiveBindingManageRequest requestModels:^(NSArray * _Nullable bindingData, NSArray * _Nullable unBindingData) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if(!strongSelf) return;
strongSelf.bindingData = bindingData;
strongSelf.unBindingData = unBindingData;
[strongSelf.tableView reloadData];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = RGBOF(0xf4f4f4);
self.title = @"绑定管理";
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
[self loadData];
[self createUI];
}
- (void)createUI{
[self.view addSubview:self.tableView];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top).with.offset(kVerticalStatusHeight+44);
make.left.equalTo(self.view.mas_left).with.offset(0);
make.right.equalTo(self.view.mas_right).with.offset(-0);
make.bottom.equalTo(self.view.mas_bottom).with.offset(-0);
}];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(section == 0){
return self.bindingData.count;
}else if(section == 1){
return self.unBindingData.count;
}else{
return 0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 80;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveBindingManageCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveBindingManageCell forIndexPath:indexPath];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.delegate = self;
if(indexPath.section == 0){
if(self.bindingData.count > 0){
cell.model = self.bindingData[indexPath.row];
}
}else if(indexPath.section == 1){
if(self.unBindingData.count > 0){
cell.model = self.unBindingData[indexPath.row];
}
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 40.0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.0000001f;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSArray *array = @[@"您已绑定网家家手机号账号", @"其他绑定方式"];
CNLiveBindingManageHeaderView *header = [tableView dequeueReusableHeaderFooterViewWithIdentifier:kCNLiveBindingManageHeaderView];
header.text = array[section];
return header;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
}
/*
#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.
}
*/
#pragma mark - Lazy loading
- (UITableView *)tableView {
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];
_tableView.backgroundColor = RGBOF(0xf4f4f4);
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.showsVerticalScrollIndicator = NO;
_tableView.showsHorizontalScrollIndicator = NO;
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
[_tableView registerClass:[CNLiveBindingManageCell class] forCellReuseIdentifier:kCNLiveBindingManageCell];
[_tableView registerClass:[CNLiveBindingManageHeaderView class] forHeaderFooterViewReuseIdentifier:kCNLiveBindingManageHeaderView];
}
return _tableView;
}
@end