@@ -44,6 +44,10 @@ - (void)viewDidLoad{
44
44
});
45
45
_myRefreshControl = [[ODRefreshControl alloc ] initInScrollView: self .myTableView];
46
46
[_myRefreshControl addTarget: self action: @selector (refresh ) forControlEvents: UIControlEventValueChanged];
47
+ }
48
+
49
+ - (void )viewWillAppear : (BOOL )animated {
50
+ [super viewWillAppear: animated];
47
51
[self refresh ];
48
52
}
49
53
@@ -100,9 +104,9 @@ - (BOOL)findLocalFile{
100
104
[pro_dict[@" list" ] addObject: fileUrl];
101
105
}
102
106
}
103
- return YES ;
104
107
}
105
- return NO ;
108
+ [self .myTableView reloadData ];
109
+ return localFileUrlList.count > 0 ;
106
110
}
107
111
108
112
- (void )refreshProjectNameWithProjects : (Projects *)projects {
@@ -130,7 +134,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
130
134
NSDictionary *pro_dict = _projectList_dict[key];
131
135
132
136
[cell setProjectName: pro_dict[@" name" ] fileCount: [(NSArray *)pro_dict[@" list" ] count ]];
133
-
137
+ cell. delegate = self;
134
138
[tableView addLineforPlainCell: cell forRowAtIndexPath: indexPath withLeftSpace: kPaddingLeftWidth ];
135
139
return cell;
136
140
}
@@ -151,4 +155,62 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
151
155
152
156
[self .navigationController pushViewController: vc animated: YES ];
153
157
}
158
+
159
+ #pragma mark SWTableViewCellDelegate
160
+ - (BOOL )swipeableTableViewCellShouldHideUtilityButtonsOnSwipe : (SWTableViewCell *)cell {
161
+ return YES ;
162
+ }
163
+ - (BOOL )swipeableTableViewCell : (SWTableViewCell *)cell canSwipeToState : (SWCellState)state {
164
+ return YES ;
165
+ }
166
+
167
+ - (void )swipeableTableViewCell : (SWTableViewCell *)cell didTriggerRightUtilityButtonWithIndex : (NSInteger )index {
168
+ [cell hideUtilityButtonsAnimated: YES ];
169
+
170
+ NSIndexPath *indexPath = [self .myTableView indexPathForCell: cell];
171
+ NSString *projectId = _projectId_list[indexPath.row];
172
+
173
+ __weak typeof (self) weakSelf = self;
174
+ UIActionSheet *actionSheet = [UIActionSheet bk_actionSheetCustomWithTitle: @" 确定要删除该文件夹内所有本地文件吗?" buttonTitles: nil destructiveTitle: @" 确认删除" cancelTitle: @" 取消" andDidDismissBlock: ^(UIActionSheet *sheet, NSInteger index ) {
175
+ if (index == 0 ) {
176
+ [weakSelf deleteFilesWithProjectIdList: @[projectId]];
177
+ }
178
+ }];
179
+ [actionSheet showInView: self .view];
180
+ }
181
+
182
+ #pragma mark Delete
183
+ - (void )deleteFilesWithProjectIdList : (NSArray *)projectIdList {
184
+ NSMutableArray *urlList = [NSMutableArray new ];
185
+ for (NSString *key in projectIdList) {
186
+ NSDictionary *pro_dict = _projectList_dict[key];
187
+ NSArray *curList = pro_dict[@" list" ];
188
+ if (curList.count > 0 ) {
189
+ [urlList addObjectsFromArray: curList];
190
+ }
191
+ }
192
+ [self deleteFilesWithUrlList: urlList];
193
+ }
194
+
195
+ - (void )deleteFilesWithUrlList : (NSArray *)urlList {
196
+ @weakify (self);
197
+ dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_DEFAULT, 0 ), ^{
198
+ NSFileManager *fm = [NSFileManager defaultManager ];
199
+ for (NSURL *fileUrl in urlList) {
200
+ NSString *filePath = fileUrl.path ;
201
+ if ([fm fileExistsAtPath: filePath]) {
202
+ NSError *fileError;
203
+ [fm removeItemAtPath: filePath error: &fileError];
204
+ if (fileError) {
205
+ [NSObject showError: fileError];
206
+ }
207
+ }
208
+ }
209
+ dispatch_async (dispatch_get_main_queue (), ^{
210
+ @strongify (self);
211
+ [self findLocalFile ];
212
+ [NSObject showHudTipStr: @" 本地文件删除成功" ];
213
+ });
214
+ });
215
+ }
154
216
@end
0 commit comments