SetTableView.m
5.0 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
//
// SetTableView.m
// DreamSleep
//
// Created by peter on 2022/4/17.
//
#import "SetTableView.h"
/// 设置自定义数据模型
@interface SetModel : NSObject
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *detail;
+ (NSArray *)getAllSetDatas;
@end
@implementation SetModel
+ (NSArray *)getAllSetDatas {
NSArray *titles = @[@"应用版本及升级", @"用户协议", @"隐私政策", @"清除缓存"];
NSString *version = [NSString stringWithFormat:@"当前版本%@", [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];
NSArray *details = @[version, @"", @"", @"10.0M"];
NSMutableArray *tmpArr = [NSMutableArray array];
for (int i = 0; i < 4; i++) {
SetModel *m = [SetModel new];
m.title = titles[i];
m.detail = details[i];
[tmpArr addObject:m];
}
return [tmpArr copy];
}
@end
/// 设置自定义Cell
@interface SetCell : UITableViewCell
@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *detailLab;
@property (nonatomic, strong) UIImageView *rightIcon;
- (void)updateConstraintsWithModel:(SetModel *)model;
@end
@implementation SetCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, ColorFromHex(0x1F263F), DSWhite);
self.accessoryView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"moreIcon"]];
self.titleLab = [UILabel dkLabWithFont:BoldFont(15.0)];
[self addSubview:self.titleLab];
self.detailLab = [UILabel labWithFont:SysFont(14.0)];
self.detailLab.dk_textColorPicker = DKColorPickerWithColors(SubTitleColor, ColorFromHex(0x8C8F9D), DSWhite);
[self addSubview:self.detailLab];
}
return self;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
self.selectedBackgroundView = [[UIView alloc] initWithFrame:self.frame];
self.selectedBackgroundView.backgroundColor = DSClearColor;
[super setSelected:selected animated:animated];
}
- (void)updateConstraintsWithModel:(SetModel *)model {
self.titleLab.text = model.title;
self.detailLab.text = model.detail;
[self.titleLab sizeToFit];
[self.detailLab sizeToFit];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self).offset(15);
make.centerY.equalTo(self);
}];
[self.detailLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(self.accessoryView.mas_left).offset(-8);
make.centerY.equalTo(self);
}];
}
@end
@interface SetTableView () <UITableViewDelegate>
@property (nonatomic, strong) DSDataSource *setDataSource;
@property (nonatomic, strong) NSArray *dataArr;
@end
@implementation SetTableView
- (instancetype)initWithDelegate:(id<SetTableViewDelegate>)delegate {
if (self = [super initWithFrame:CGRectMake(15, 15, kScreenWidth - 30, 348) style:UITableViewStylePlain]) {
self.dataArr = [SetModel getAllSetDatas];
self.setDelegate = delegate;
[self cornerRadius:10];
self.scrollEnabled = NO;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, ColorFromHex(0x1F263F), DSWhite);
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.setDataSource addDataArray:self.dataArr];
}
return self;
}
- (DSDataSource *)setDataSource {
if (!_setDataSource) {
CellConfigureBlock cellBlock = ^(SetCell * cell, SetModel * model, NSIndexPath * indexPath) {
[cell updateConstraintsWithModel:model];
};
NSString * const setCellID = @"SetCellID";
_setDataSource = [[DSDataSource alloc] initWithIdentifier:setCellID datas:@[] isSection:NO configureBlock:cellBlock];
self.dataSource = _setDataSource;
self.delegate = self;
[self registerClass:[SetCell class] forCellReuseIdentifier:setCellID];
}
return _setDataSource;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
return 50;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) { // 应用版本升级
// 跳转到AppStore
[DSProgressHUD showToast:@"暂无新版本"];
} else if (indexPath.row == 3) { // 清除缓存
[DSProgressHUD showToast:@"清除成功"];
SetModel *m = self.dataArr[indexPath.row];
m.detail = @"0M";
[tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:indexPath.row inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
} else {
if (self.setDelegate && [self.setDelegate respondsToSelector:@selector(didSelectRowAtIndexPath:)]) {
[self.setDelegate didSelectRowAtIndexPath:indexPath];
}
}
}
@end