MyFeedListController.m
8.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
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
#import "MyFeedListController.h"
#import "MyFeedCell.h"
#import "FeedbackRequestModel.h"
#import "FeedbackDetailController.h"
@interface MyFeedListController () <UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *feedbackIV;
@property (nonatomic, strong) NSArray *listData;
@end
@implementation MyFeedListController
- (instancetype)initWithDelegate:(id<MyFeedListControllerDelegate>)delegate {
if (self = [super init]) {
_delegate = delegate;
_listData = [NSArray array];
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.navigationItem.title = @"我的反馈";
self.view.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
[self.view addSubview:self.feedbackIV];
WS(weakSelf);
self.feedbackIV.mj_header = [DSGifHeader headerWithRefreshingBlock:^{
[FeedbackRequestModel queryUserAdviceListWithCompletion:^(FeedbackRequestModel * _Nonnull requestModel) {
[weakSelf.feedbackIV.mj_header endRefreshing];
if (requestModel.resCode == DSResCodeSuccess) {
weakSelf.listData = requestModel.adviceListArr;
[weakSelf.feedbackIV reloadData];
}
}];
}];
[self.feedbackIV.mj_header beginRefreshing];
}
#pragma mark - UITableViewDelegate && UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.listData.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 110.f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 7.5;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 7.5)];
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
return 7.5;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 7.5)];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyFeedCell *cell = [tableView dequeueReusableCellWithIdentifier:cardRadiusCellIdentifier];
MyFeedModel *model = self.listData[indexPath.row];
[cell updateUI:model];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
MyFeedModel *model = self.listData[indexPath.row];
if (model.read_status == 0) {
model.read_status = 1;
if (self.delegate && [self.delegate respondsToSelector:@selector(didClickMessage)]) {
[self.delegate didClickMessage];
}
}
FeedbackDetailController *detailVC = [FeedbackDetailController new];
detailVC.advice_id = model.feed_id;
[self.navigationController pushViewController:detailVC animated:YES];
}
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{
UIRectCorner corner = UIRectCornerAllCorners;
[cell insetCardViewWithCorners:corner
edgeInsets:UIEdgeInsetsMake(7.5, 15.0, 7.5, 15.0)
radius:12.f
borderWidth:1.f
borderCorlor:DSClearColor
backgroundColor:([self.dk_manager.themeVersion isEqualToString:DKThemeVersionNormal] ? DSWhite : CornerViewDarkColor)];
}
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath {
dispatch_async(dispatch_get_main_queue(), ^{
[self setupSlideBtnWithEditingIndexPath:indexPath];
});
}
- (NSArray*)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
NSMutableArray *mArr = [NSMutableArray arrayWithArray:self.listData];
MyFeedModel *model = self.listData[indexPath.row];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"删除按钮宽度" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
// 删除反馈请求
[DSProgressHUD showProgressHUDWithInfo:@""];
[FeedbackRequestModel deleteAdviceFeedbackWithAdviceID:model.feed_id completion:^(FeedbackRequestModel * _Nonnull requestModel) {
[DSProgressHUD dissmissProgressHUD];
if (requestModel.resCode == DSResCodeSuccess) {
[DSProgressHUD showToast:@"删除成功"];
[mArr removeObjectAtIndex:indexPath.row];
self.listData = [mArr copy];
[tableView reloadData];
}
}];
// 这句很重要,退出编辑模式,隐藏左滑菜单
[tableView setEditing:NO animated:YES];
}];
// 主动调用代理方法,防止快速滑动时显示原生
[self tableView:self.feedbackIV willBeginEditingRowAtIndexPath:indexPath];
return @[deleteAction];
}
#pragma mark - 设置左滑按钮的样式
- (void)setupSlideBtnWithEditingIndexPath:(NSIndexPath *)editingIndexPath {
// 判断系统是否是iOS13及以上版本
if (@available(iOS 13.0, *)) {
for (UIView *subView in self.feedbackIV.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"_UITableViewCellSwipeContainerView")] && [subView.subviews count] >= 1) {
// 修改图片
UIView *remarkContentView = subView.subviews.firstObject;
[self setupRowActionView:remarkContentView];
}
}
return;
}
// 判断系统是否是 iOS11 及以上版本
if (@available(iOS 11.0, *)) {
for (UIView *subView in self.feedbackIV.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UISwipeActionPullView")] && [subView.subviews count] >= 1) {
// 修改图片
UIView *remarkContentView = subView;
[self setupRowActionView:remarkContentView];
}
}
return;
}
// iOS11 以下的版本
MyFeedCell *cell = [self.feedbackIV cellForRowAtIndexPath:editingIndexPath];
for (UIView *subView in cell.subviews) {
if ([subView isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")] && [subView.subviews count] >= 1) {
// 修改图片
UIView *remarkContentView = subView;
[self setupRowActionView:remarkContentView];
}
}
}
- (void)setupRowActionView:(UIView *)rowActionView {
rowActionView.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
// 拿到原来的删除按钮
UIButton *oriDeleteBtn = rowActionView.subviews.firstObject;
oriDeleteBtn.hidden = YES;
// 自定义删除按钮
UIButton *cusDeleteBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, 7.5, oriDeleteBtn.width - 15, oriDeleteBtn.height - 15)];
[cusDeleteBtn cornerRadius:12];
cusDeleteBtn.dk_backgroundColorPicker = DKColorPickerWithColors(DSWhite, CornerViewDarkColor, DSWhite);
[cusDeleteBtn dk_setImage:DKImagePickerWithNames(@"delete_feed_icon", @"dk_delete_feed_icon", @"delete_feed_icon") forState:UIControlStateNormal];
[rowActionView addSubview:cusDeleteBtn];
}
#pragma mark - lazy
- (UITableView *)feedbackIV {
if (!_feedbackIV) {
_feedbackIV = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight - kTopHeight(0)) style:UITableViewStylePlain];
_feedbackIV.delegate = self;
_feedbackIV.dataSource = self;
_feedbackIV.dk_backgroundColorPicker = DKColorPickerWithKey(VCViewBG);
_feedbackIV.showsVerticalScrollIndicator = NO;
[_feedbackIV registerClass:[MyFeedCell class] forCellReuseIdentifier:cardRadiusCellIdentifier];
_feedbackIV.separatorStyle = UITableViewCellSeparatorStyleNone;
}
return _feedbackIV;
}
#pragma mark - 品牌模式
- (NaviStyle)navigationBarStyle {
return NaviStyleDefault;
}
@end