HomeTableView.m
3.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
//
// HomeTableView.m
// DreamSleep
//
// Created by peter on 2022/4/8.
//
#import "HomeTableView.h"
#import "DSGifHeader.h"
#import "HomeHeaderView.h"
#import "SafeSleepCell.h"
#import "HomeRequestModel.h"
#import "SafeSleepRequestModel.h"
@interface HomeTableView () <UITableViewDelegate>
@property (nonatomic, strong) HomeHeaderView *headerView;
@property (nonatomic, strong) DSDataSource *homeDataSource;
@end
@implementation HomeTableView
- (instancetype)initDemo {
if (self = [super initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight) style:UITableViewStylePlain]) {
self.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
self.separatorStyle = UITableViewCellSeparatorStyleNone;
self.showsVerticalScrollIndicator = NO;
// iOS 15适配UITableView内容自动下移22像素BUG
if (@available(iOS 15.0, *)) {
self.sectionHeaderTopPadding = 0;
}
[self.homeDataSource addDataArray:[SafeSleepModel getDatas]];
self.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
[HomeRequestModel queryBannerListWithCompletion:^(HomeRequestModel * _Nonnull requestModel) {
[self.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
[self.headerView updateBannerWithListData:requestModel.bannerListData];
}
}];
// [SafeSleepRequestModel getCourseListDataWithSubID:6 completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
// [self.mj_header endRefreshing];
// }];
// [SafeSleepRequestModel getCourseListDataWithSubID:18 completion:^(SafeSleepRequestModel * _Nonnull requestModel) {
// [self.mj_header endRefreshing];
// }];
}];
[self.mj_header beginRefreshing];
}
return self;
}
- (DSDataSource *)homeDataSource {
if (!_homeDataSource) {
CellConfigureBlock cellBlock = ^(SafeSleepCell * cell, SafeSleepModel * model, NSIndexPath * indexPath) {
[cell configureCellWithModel:model indexPath:indexPath];
};
NSString * const safeSleepCellID = @"safeSleepCellID";
_homeDataSource = [[DSDataSource alloc] initWithIdentifier:safeSleepCellID datas:@[] isSection:NO configureBlock:cellBlock];
self.dataSource = _homeDataSource;
self.delegate = self;
[self registerClass:[SafeSleepCell class] forCellReuseIdentifier:safeSleepCellID];
self.tableHeaderView = self.headerView;
}
return _homeDataSource;
}
- (HomeHeaderView *)headerView {
if (!_headerView) {
// banner高度
CGFloat bannerH = 2*(kScreenWidth - 48)/5.0;
// 三分钟即刻入睡按钮宽度
CGFloat width = (kScreenWidth - 2*15 - 14)/2;
CGFloat height = 15 + bannerH + 24 + 133*width/165.0;
_headerView = [[HomeHeaderView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, height)];
_headerView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
}
return _headerView;
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 300;
if (indexPath.row == 0) {
height = 206;
} else if (indexPath.row == 1) {
height = 196;
}
return height;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 0.001;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 0.001;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 0.001)];
}
@end