ReplyDetailView.m
4.7 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
//
// ReplyDetailView.m
// DreamSleep
//
// Created by peter on 2022/10/9.
//
#import "ReplyDetailView.h"
#import "MajorCommentCell.h"
#import "ReplyCell.h"
#define kSectionHeaderHeight 48
#define kSectionFooterHeight 8
@interface ReplyDetailView () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) NSArray *detailListArr;
@end
@implementation ReplyDetailView
- (instancetype)initWithDelegate:(id<ReplyDetailViewDelegate>)replyDelegate {
if (self = [super initWithFrame:CGRectZero style:UITableViewStyleGrouped]) {
self.replyDelegate = replyDelegate;
self.detailListArr = [NSArray array];
self.delegate = self;
self.dataSource = self;
self.showsVerticalScrollIndicator = NO;
self.separatorStyle = UITableViewCellSeparatorStyleNone;
[self registerClass:[MajorCommentCell class] forCellReuseIdentifier:NSStringFromClass([MajorCommentCell class])];
[self registerClass:[ReplyCell class] forCellReuseIdentifier:NSStringFromClass([ReplyCell class])];
self.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
self.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 24 + Bottom_SafeArea_Height)];;
self.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
}
return self;
}
#pragma mark - public
- (void)updateReplyDetailView:(NSArray *)replyGroupData {
if (replyGroupData.count) {
self.detailListArr = replyGroupData;
[self reloadData];
}
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return self.detailListArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return 1;
} else {
NSArray *replyList = self.detailListArr[section];
return replyList.count;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
CommentModel *commentModel = self.detailListArr[0];
return [commentModel cellHeight];
} else {
NSArray *replyList = self.detailListArr[indexPath.section];
ReplyModel *replyModel = replyList[indexPath.row];
return [replyModel cellHeight];
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return section == 0 ? CGFLOAT_MIN : kSectionHeaderHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *header = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 0)];
header.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, DarkColor, DSWhite);
if (section == 0) {
header.height = 0;
} else {
UILabel *totalReplyCountLab = [UILabel labWithFont:BoldFont(15)];
totalReplyCountLab.dk_textColorPicker = DKColorPickerWithKey(Dk_TITLE);
totalReplyCountLab.origin = CGPointMake(30, 15);
[header addSubview:totalReplyCountLab];
header.height = kSectionHeaderHeight;
NSArray *replyList = self.detailListArr[section];
totalReplyCountLab.text = replyList.count ? [NSString stringWithFormat:@"全部回复(%ld)", replyList.count] : @"暂无回复";
[totalReplyCountLab sizeToFit];
}
return header;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return section == self.detailListArr.count - 1 ? CGFLOAT_MIN : kSectionFooterHeight;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
UIView *footer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, section == self.detailListArr.count - 1 ? CGFLOAT_MIN : kSectionFooterHeight)];
footer.dk_backgroundColorPicker = DKColorPickerWithColors(BGColor, AlertDarkColor, DSWhite);
return footer;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
MajorCommentCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([MajorCommentCell class]) forIndexPath:indexPath];
cell.commentModel = self.detailListArr[indexPath.section];
return cell;
} else {
ReplyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ReplyCell class]) forIndexPath:indexPath];
NSArray *replyList = self.detailListArr[indexPath.section];
ReplyModel *replyModel = replyList[indexPath.row];
cell.replyModel = replyModel;
return cell;
}
}
@end