Skip to content

Commit

Permalink
沙盒浏览器支持文件和文件夹删除功能
Browse files Browse the repository at this point in the history
  • Loading branch information
yixiang committed Oct 20, 2018
1 parent 31691b7 commit 2010bf3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,20 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
return cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
return YES;
}

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{
return @"删除";
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
DoraemonSandboxModel *model = _dataArray[indexPath.row];
[self deleteByDoraemonSandboxModel:model];
}


#pragma mark- UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 48;
Expand Down Expand Up @@ -183,4 +197,10 @@ - (void)shareFileWithPath:(NSString *)filePath{
[self presentViewController:controller animated:YES completion:nil];
}

- (void)deleteByDoraemonSandboxModel:(DoraemonSandboxModel *)model{
NSFileManager *fm = [NSFileManager defaultManager];
[fm removeItemAtPath:model.path error:nil];
[self loadPath:_currentDirModel.path];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,18 @@ - (void)addFile{
NSString *json = [self dictToJsonStr:dic];

NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *filePath = [docDir stringByAppendingPathComponent:@"json.txt"];
NSString *dirPath = [docDir stringByAppendingPathComponent:@"test"];
NSFileManager *fm = [NSFileManager defaultManager];
BOOL isDir = NO;
BOOL existed = [fm fileExistsAtPath:dirPath isDirectory:&isDir];
if (!(isDir && existed)) {
[fm createDirectoryAtPath:dirPath withIntermediateDirectories:YES attributes:nil error:nil];
}
NSString *filePath = [dirPath stringByAppendingPathComponent:@"json.txt"];
NSString *filePath2 = [dirPath stringByAppendingPathComponent:@"json2.txt"];

[json writeToFile:filePath atomically:YES encoding:NSUTF8StringEncoding error:nil];

[json writeToFile:filePath2 atomically:YES encoding:NSUTF8StringEncoding error:nil];
}

- (void)addImageFile{
Expand Down

0 comments on commit 2010bf3

Please sign in to comment.