CNLiveUserInfoController.m
6.73 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
//
// CNLiveBMineController.m
// CNLiveBMineModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveUserInfoController.h"
#import "MJExtension.h"
#import "QMUIKit.h"
#import "CNUserInfoManager.h"
#import "CNLiveServices.h"
#import "CNLiveNavigationBar.h"
#import "CNLiveUserInfoCell.h"
#import "CNLiveUserInfoModel.h"
#import "CNLiveInfoUpdateController.h"
#import "CNLiveUserInfoNotification.h"
@interface CNLiveUserInfoController ()<UITableViewDelegate, UITableViewDataSource>{
UIImage *_image;
}
@property (nonatomic, strong) CNLiveNavigationBar *navigationBar;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *data;
@end
@implementation CNLiveUserInfoController
#pragma mark - 加载数据
- (void)loadData {
NSArray *data = @[
@{
@"layout":@"2",
@"data":@"0",
@"title":@"头像",
@"info":CNUserShareModel.faceUrl?CNUserShareModel.faceUrl:@"",
@"height":@"81",
@"lineHeight":@"0.5"
},
@{
@"layout":@"1",
@"data":@"1",
@"title":@"昵称",
@"info":CNUserShareModel.nickname?CNUserShareModel.nickname:@"",
@"height":@"51",
@"lineHeight":@"0.5"
},
@{
@"layout":@"1",
@"data":@"2",
@"title":@"性别",
@"info":CNUserShareModel.gender?CNUserShareModel.gender:@"未知",
@"height":@"60",
@"lineHeight":@"10"
},
@{
@"layout":@"1",
@"data":@"3",
@"title":@"地区",
@"info":CNUserShareModel.location?CNUserShareModel.location:@"",
@"height":@"60",
@"lineHeight":@"10"
}
];
for(NSDictionary *dic in data){
[self.data addObject:[CNLiveUserInfoModel mj_objectWithKeyValues:dic]];
}
[self.tableView reloadData];
}
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
if (@available(iOS 11, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
[CNLiveUserInfoNotification addUserInfoUpdateObserver:self selector:@selector(userInfoUpdateNotification:)];
[self createSubViews];
[self loadData];
}
- (void)dealloc {
[CNLiveUserInfoNotification removeObserver:self];
}
- (void)createSubViews {
[self.view addSubview:self.navigationBar];
[self.view addSubview:self.tableView];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
CNLiveUserInfoModel *model = self.data[indexPath.row];
return model.height;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveUserInfoCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveUserInfoCell];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
CNLiveUserInfoModel *model = self.data[indexPath.row];
cell.model = model;
if(_image){
cell.image = _image;
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CNLiveUserInfoModel *model = self.data[indexPath.row];
switch (model.dataType) {
case CNLiveUserInfoDataTypeCode:
{
id<CNLiveQrCodeServiceProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveQrCodeServiceProtocol)];
[service pushToMyQrCodeController:NO];
}
break;
default:
{
CNLiveInfoUpdateController *vc = [[CNLiveInfoUpdateController alloc]initWithModel:model];
[self.navigationController pushViewController:vc animated:YES];
}
break;
}
}
#pragma mark - 监听
// 更新用户信息
- (void)userInfoUpdateNotification:(NSNotification *)noti{
//使用userInfo处理消息
NSDictionary *dic = [noti userInfo];
CNLiveUserInfoDataType dataType = [[dic objectForKey:@"dataType"] integerValue];
NSString *info = [dic objectForKey:@"info"];
// 更新cell展示信息
for(CNLiveUserInfoModel *model in self.data){
if(dataType == model.dataType){
model.info = info;
break;
}
}
[self.tableView reloadData];
}
#pragma mark - 懒加载
- (CNLiveNavigationBar *)navigationBar {
if (!_navigationBar) {
_navigationBar = [CNLiveNavigationBar navigationBar];
_navigationBar.title.text = @"个人资料";
__weak typeof(self) weakSelf = self;
_navigationBar.onClickLeftButton = ^{
[weakSelf goBack];
};
}
return _navigationBar;
}
- (NSMutableArray *)data {
if (!_data) {
_data = [NSMutableArray array];
}
return _data;
}
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop) style:UITableViewStylePlain];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.bounces = NO;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
[_tableView registerClass:[CNLiveUserInfoCell class] forCellReuseIdentifier:kCNLiveUserInfoCell];
}
return _tableView;
}
#pragma mark - 响应方法
- (void)goBack {
if (self.presentingViewController != nil) {
[self dismissViewControllerAnimated:YES completion:nil];
}
else {
[self.navigationController popViewControllerAnimated:YES];
}
}
@end