OfficialNoticeController.m
3.2 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
//
// OfficialNoticeController.m
// DreamSleep
//
// Created by peter on 2022/10/11.
//
#import "OfficialNoticeController.h"
#import "OfficialNotiCell.h"
#import "OfficialNotiViewModel.h"
@interface OfficialNoticeController () <UITableViewDelegate>
@property (nonatomic, strong) DSDataSource *dataSource;
@property (nonatomic, strong) UITableView *listView;
@end
@implementation OfficialNoticeController
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"官方通知";
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.dataSource addDataArray:@[]];
[self.listView.mj_header beginRefreshing];
}
- (void)fireHandler {
[super fireHandler];
[self.listView.mj_header beginRefreshing];
}
- (void)getListDataRequest {
[OfficialNotiViewModel queryUserOfficeMessagesWithCompletion:^(OfficialNotiViewModel * _Nonnull viewModel) {
[self.listView.mj_header endRefreshing];
if (viewModel.resCode == DSResCodeSuccess) {
if (viewModel.listArr.count == 0) {
[self updateDefalutView:DefaultTypeEmpty info:@""];
} else {
[self.dataSource addDataArray:viewModel.listArr];
}
[self.listView reloadData];
} else {
[self updateDefalutView:DefaultTypeNet info:viewModel.errMessage];
}
}];
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
OfficialNotiModel *model = self.dataSource.dataArray[indexPath.row];
return [model cellHeight];
}
#pragma mark - lazy
- (DSDataSource *)dataSource {
if (!_dataSource) {
CellConfigureBlock cellBlock = ^(OfficialNotiCell * cell, OfficialNotiModel * model, NSIndexPath * indexPath) {
cell.officialNotiModel = model;
};
_dataSource = [[DSDataSource alloc] initWithIdentifier:NSStringFromClass([OfficialNotiCell class]) datas:@[] isSection:NO configureBlock:cellBlock];
UITableView *listView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
listView.separatorStyle = UITableViewCellSeparatorStyleNone;
listView.delegate = self;
listView.dataSource = _dataSource;
listView.showsVerticalScrollIndicator = NO;
listView.backgroundColor = DSClearColor;
listView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
[listView registerClass:[OfficialNotiCell class] forCellReuseIdentifier:NSStringFromClass([OfficialNotiCell class])];
listView.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 25)];
listView.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 24 + Bottom_SafeArea_Height)];
[self.view addSubview:listView];
self.listView = listView;
WS(weakSelf);
self.listView.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
[weakSelf getListDataRequest];
}];
[self.listView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
}
return _dataSource;
}
@end