ProfileTableView.m
10.9 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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
//
// ProfileTableView.m
// DreamSleep
//
// Created by peter on 2022/5/18.
//
#import "ProfileTableView.h"
#import "ProfileHeaderView.h"
#pragma mark - ProfileModel
@interface ProfileModel : NSObject
@property (nonatomic, copy) NSString *leftIcon;
@property (nonatomic, copy) NSString *dk_leftIcon;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *rightIcon;
@property (nonatomic, copy) NSString *dk_rightIcon;
@end
@implementation ProfileModel
+ (NSArray *)getGroupDataArr {
NSArray *leftIcon_group1 = @[@"ic_person_fankui_normal", @"ic_person_shezhi_normal", @"ic_person_yaoqing_normal", @"ic_person_guanyuwomen_normal"];
NSArray *dk_leftIcon_group1 = @[@"dk_ic_person_fankui_normal", @"dk_ic_person_shezhi_normal", @"dk_ic_person_yaoqing_normal", @"dk_ic_person_guanyuwomen_normal"];
NSArray *title_group1 = @[@"意见反馈", @"系统设置", @"邀请好友", @"关于我们"];
NSArray *leftIcon_group2 = @[@"ic_person_xiaochengxu_normal", @"ic_person_gongzhonghao_normal", @"ic_person_kefu_normal"];
NSArray *dk_leftIcon_group2 = @[@"dk_ic_person_xiaochengxu_normal", @"dk_ic_person_gongzhonghao_normal", @"dk_ic_person_kefu_normal"];
NSArray *title_group2 = @[@"前往小程序", @"关注公众号", @"添加客服微信"];
NSMutableArray *group1Arr = [NSMutableArray array];
for (int i = 0; i < leftIcon_group1.count; i++) {
ProfileModel *model = [ProfileModel new];
model.leftIcon = leftIcon_group1[i];
model.dk_leftIcon = dk_leftIcon_group1[i];
model.title = title_group1[i];
model.rightIcon = @"moreIcon";
model.dk_rightIcon = @"moreIcon";
[group1Arr addObject:model];
}
NSMutableArray *group2Arr = [NSMutableArray array];
for (int i = 0; i < leftIcon_group2.count; i++) {
ProfileModel *model = [ProfileModel new];
model.leftIcon = leftIcon_group2[i];
model.dk_leftIcon = dk_leftIcon_group2[i];
model.title = title_group2[i];
model.rightIcon = @"moreIcon";
model.dk_rightIcon = @"moreIcon";
[group2Arr addObject:model];
}
return @[[group1Arr copy], [group2Arr copy]];
}
@end
#pragma mark - ProfileCell
@interface ProfileCell : UITableViewCell
@property (nonatomic, strong) ProfileModel *model;
@property (nonatomic, strong) UIImageView *leftIV;
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UIImageView *rightIV;
@end
@implementation ProfileCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.selectionStyle = UITableViewCellSelectionStyleNone;
self.backgroundColor = DSClearColor;
[self.contentView addSubview:self.leftIV];
[self.contentView addSubview:self.titleLab];
[self.contentView addSubview:self.rightIV];
[self.leftIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.contentView).offset(23);
make.centerY.equalTo(self.contentView);
make.width.height.equalTo(@30);
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.leftIV.mas_right).offset(8);
make.centerY.equalTo(self.contentView);
make.right.equalTo(self.rightIV.mas_left).offset(-8);
}];
[self.rightIV mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.contentView).offset(-23);
make.centerY.equalTo(self.contentView);
make.width.height.equalTo(@30);
}];
}
return self;
}
- (void)setModel:(ProfileModel *)model {
_model = model;
self.leftIV.dk_imagePicker = DKImagePickerWithNames(model.leftIcon, model.dk_leftIcon, model.leftIcon);
self.titleLab.text = model.title;
self.rightIV.dk_imagePicker = DKImagePickerWithNames(model.rightIcon, model.dk_rightIcon, model.rightIcon);
}
- (UIImageView *)leftIV {
if (!_leftIV) {
_leftIV = [UIImageView new];
}
return _leftIV;
}
- (UILabel *)titleLab {
if (!_titleLab) {
_titleLab = [UILabel labWithFont:SysFont(15)];
_titleLab.dk_textColorPicker = DKColorPickerWithColors(MainTextColor, DkTitleColor, DkTitleColor);
}
return _titleLab;
}
- (UIImageView *)rightIV {
if (!_rightIV) {
_rightIV = [UIImageView new];
}
return _rightIV;
}
@end
#pragma mark - ProfileTableView
@interface ProfileTableView () <UITableViewDataSource, UITableViewDelegate, ProfileHeaderViewDelegate>
@property (nonatomic, strong) NSArray *profileGroupArr;
@property (nonatomic, strong) ProfileHeaderView *profileHeaderView;
@property (nonatomic, strong) UIView *footerView;
@property (nonatomic, strong) UIImageView *introduceIV;
@property (nonatomic, strong) NSURL *introduceUrl;
@property (nonatomic, strong) ExceptionDefaultView *exceptionView;
@end
@implementation ProfileTableView
- (instancetype)initWithDelegate:(id<ProfileTableViewDelegate>)profileDelegate {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTabBarHeight) style:UITableViewStyleGrouped]) {
_profileDelegate = profileDelegate;
self.backgroundColor = DSClearColor;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsVerticalScrollIndicator = NO;
self.delegate = self;
self.dataSource = self;
self.tableHeaderView = self.profileHeaderView;
self.tableFooterView = self.footerView;
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[self registerClass:[ProfileCell class] forCellReuseIdentifier:NSStringFromClass([ProfileCell class])];
}
return self;
}
#pragma mark - UITableViewDataSource && UITableViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.profileGroupArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *dataArr = self.profileGroupArr[section];
return dataArr.count;
}
- (nonnull UITableViewCell *)tableView:(nonnull UITableView *)tableView cellForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
NSArray *dataArr = self.profileGroupArr[indexPath.section];
ProfileModel *model = dataArr[indexPath.row];
ProfileCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ProfileCell class]) forIndexPath:indexPath];
cell.model = model;
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 48;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
if (section == 0) {
UIView *footView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 8)];
footView.dk_backgroundColorPicker = DKColorPickerWithColors(ColorFromHex(0xF0F0F0), AlertDarkColor, DSWhite);
return footView;
} else {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return (section == 0) ? 8 : 0.001;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(didSelectedIndexPath:)]) {
[self.profileDelegate didSelectedIndexPath:indexPath];
}
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView {
CGFloat offset = scrollView.contentOffset.y;
if (offset >= 0) {
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(showNaviBar:)]) {
[self.profileDelegate showNaviBar:offset/kTopHeight(0)];
}
}
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(isUpdateStatusStyle:)]) {
[self.profileDelegate isUpdateStatusStyle:(offset >= 2 ? YES : NO)];
}
}
#pragma mark - Action
- (void)tapCBTIAction {
[self.ds_viewController.navigationController pushViewController:[[DsWebController alloc] initWithLink:MYCBTI isShowNavi:NO] animated:YES];
}
#pragma mark - ProfileHeaderViewDelegate
- (void)didClickModifyUserBtn {
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(modifyUserInfoAction)] ) {
[self.profileDelegate modifyUserInfoAction];
}
}
- (void)didClickScoreTaskBtn:(NSInteger)index {
if (self.profileDelegate && [self.profileDelegate respondsToSelector:@selector(dealScoreTaskAction:)] ) {
[self.profileDelegate dealScoreTaskAction:index];
}
}
#pragma mark - lazy
- (NSArray *)profileGroupArr {
if (!_profileGroupArr) {
_profileGroupArr = [ProfileModel getGroupDataArr];
}
return _profileGroupArr;
}
- (ProfileHeaderView *)profileHeaderView {
if (!_profileHeaderView) {
_profileHeaderView = [[ProfileHeaderView alloc] initWithDelegate:self];
}
return _profileHeaderView;
}
- (UIView *)footerView {
if (!_footerView) {
CGFloat width = kScreenWidth - 30;
CGFloat height = 260*width/654.0;
_footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height + 27)];
UIImageView *introduceIV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, width, height)];
[introduceIV cornerRadius:12.0];
introduceIV.userInteractionEnabled = YES;
[_footerView addSubview:introduceIV];
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapCBTIAction)];
[introduceIV addGestureRecognizer:tapGR];
self.introduceIV = introduceIV;
[self loadImg];
}
return _footerView;
}
- (ExceptionDefaultView *)exceptionView {
if (!_exceptionView) {
WS(weakSelf);
_exceptionView = [[ExceptionDefaultView alloc] initWithType:ExceptionTypeSmall block:^{
weakSelf.exceptionView.hidden = YES;
[weakSelf loadImg];
} superView:self.footerView];
}
return _exceptionView;
}
- (void)loadImg {
WS(weakSelf);
[self.introduceIV yy_setImageWithURL:[NSURL URLWithString:@"https://img2.ydniu.com/sleep_ssmain/cbti_cover.png"] placeholder:[UIImage imageNamed:@"bannerPlaceholder"] options:YYWebImageOptionShowNetworkActivity completion:^(UIImage * _Nullable image, NSURL * _Nonnull url, YYWebImageFromType from, YYWebImageStage stage, NSError * _Nullable error) {
weakSelf.exceptionView.hidden = error ? NO : YES;
weakSelf.introduceIV.hidden = !weakSelf.exceptionView.hidden;
}];
}
@end