CNLiveMineController.m
7.15 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
//
// CNLiveBMineController.m
// CNLiveBMineModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveMineController.h"
#import "MJExtension.h"
#import "QMUIKit.h"
#import "CNLiveBServices.h"
#import <CNLiveRequestBastKit/CNLiveNetworking.h>
#import "CNUserInfoManager.h"
#import "CNLiveEnvironment.h"
#import "CNLiveCategory.h"
#import "CNLiveMineHeaderView.h"
#import "CNLiveMineCell.h"
#import "CNLiveMineModel.h"
#import "CNLiveMineRequest.h"
#import "CNLiveUserInfoController.h"
#import "CNLiveSettingController.h"
#import "CNLiveHomePageProtocol.h"
@interface CNLiveMineController()<UITableViewDelegate, UITableViewDataSource, CNLiveMineHeaderViewDelegate>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) CNLiveMineHeaderView *headerView;
@property (nonatomic, strong) NSMutableArray *data;
@end
@implementation CNLiveMineController
static const NSInteger kHEIGHT = 253;
static const CGFloat timeValue = 1.5;
#pragma mark - 加载数据
- (void)loadData {
NSArray *data = @[
// @{
// @"name":@"直播中心",
// @"image":@"CNLiveBMineModule.bundle/mine_zbzx",
// },
// @{
// @"name":@"钱包",
// @"image":@"CNLiveBMineModule.bundle/mine_qb",
// },
@{
@"name":@"设置",
@"image":@"CNLiveBMineModule.bundle/mine_sz",
}
];
for(NSDictionary *dic in data){
CNLiveMineModel *model = [CNLiveMineModel mj_objectWithKeyValues:dic];
[self.data addObject:model];
}
[self.tableView reloadData];
}
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
// [self requestCertification];
if(self.headerView){
self.headerView.frame = CGRectMake(0, -kHEIGHT, SCREEN_WIDTH, kHEIGHT);
}
self.headerView.isRefresh = YES;
[self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
if (@available(iOS 11, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
}
else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
[self createSubViews];
[self loadData];
}
- (void)createSubViews {
[self.view addSubview:self.tableView];
[self.tableView addSubview:self.headerView];
}
#pragma mark - UIScrollViewDelegate
//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
// CGPoint point = scrollView.contentOffset;
// if (point.y < -kHEIGHT) {
// CGRect rect = [self.tableView viewWithTag:666].frame;
// rect.origin.y = point.y;
// rect.size.height = -point.y;
// [self.tableView viewWithTag:666].frame = rect;
// }
//}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 45;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.data.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
CNLiveMineCell *cell = [tableView dequeueReusableCellWithIdentifier:kCNLiveMineCell];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.model = self.data[indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
CNLiveSettingController *vc = [[CNLiveSettingController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
#pragma mark - CNLiveBMineHeaderViewDelegate
- (void)headerView:(CNLiveMineHeaderView *)headerView pushToController:(CNLiveMineHeaderViewType)type{
switch (type) {
case CNLiveMineHeaderViewTypeUerInfo:
{
CNLiveUserInfoController *vc = [[CNLiveUserInfoController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
break;
case CNLiveMineHeaderViewTypeHome:
{
id<CNLiveHomePageProtocol> service = [[BeeHive shareInstance] createService:@protocol(CNLiveHomePageProtocol)];
UIViewController *vc = [service pushLiveHomePageViewController];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}
break;
}
}
#pragma mark - 请求方法
// 请求用户认证
- (void)requestCertification{
[CNLiveMineRequest certification:^(BOOL isSuccess, NSDictionary * _Nonnull data, NSError * _Nonnull error) {
if (error.code == -1001 || error.code == -1009) {
[QMUITips showError:@"网络连接已断开" inView:self.view hideAfterDelay:timeValue];
return ;
}
if (isSuccess) {
NSString *darenIdentity = [NSString stringWithFormat:@"%@",[data objectForKey:@"darenIdentity"]];
if ([darenIdentity isEqualToString:@"1"]) { //普通用户
CNUserShareModel.isDaren = 0;
self.headerView.certificationImages = @[@"mine_wjj_certification",@"mine_common",@"mine_overbadge"];
} else if ([darenIdentity isEqualToString:@"0"]) { //达人用户
CNUserShareModel.isDaren = 1;
self.headerView.certificationImages = @[@"mine_wjj_certification",@"mine_doyen", @"mine_overbadge"];
}
}
}];
}
#pragma mark - 状态栏
- (UIStatusBarStyle)preferredStatusBarStyle{
return UIStatusBarStyleLightContent;
}
#pragma mark - 响应方法
#pragma mark - 懒加载
- (NSMutableArray *)data {
if (!_data) {
_data = [NSMutableArray array];
}
return _data;
}
- (CNLiveMineHeaderView *)headerView{
if (!_headerView) {
_headerView = [[CNLiveMineHeaderView alloc]initWithFrame:CGRectMake(0, -kHEIGHT, SCREEN_WIDTH, kHEIGHT)];
_headerView.delegate = self;
_headerView.tag = 666;
}
return _headerView;
}
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT-TabBarHeight) style:UITableViewStylePlain];
_tableView.showsVerticalScrollIndicator = NO;
_tableView.scrollEnabled = NO;
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
[_tableView registerClass:[CNLiveMineCell class] forCellReuseIdentifier:kCNLiveMineCell];
_tableView.contentInset = UIEdgeInsetsMake(kHEIGHT, 0, 0, 0);
}
return _tableView;
}
@end