commitEditingStyle 并从文档目录中删除文件

发布于 2024-11-01 09:26:14 字数 972 浏览 1 评论 0原文

我正在尝试使用 commitEditingStyle 方法从文档目录中删除文件,但我面临以下问题:

在表格中,我显示保存在文档目录中的所有文件名。当用户按下“编辑”时,所有单元格都会被激活以进行删除,现在如果用户按下红色按钮并删除所有文件加上文档目录删除,它应该一次删除一个文件,而不是所有目录。以下是代码:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
NSString *documentsDirectoryPath = [paths objectAtIndex:0];  

NSMutableString *File = [documentsDirectoryPath stringByAppendingPathComponent:fileNameString];  

NSFileManager *fileManager = [NSFileManager defaultManager];  
[fileManager removeItemAtPath:File error:NULL];  

[self.downList removeObjectAtIndex:indexPath.row];  


[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];  
    }     
}  

我希望有人知道问题出在哪里。

I am trying to delete file from the document directory by use of commitEditingStyle method but I am facing following problem:

In a table I am displaying all file names which are saved in the document directory. As users press "Edit" all cells are activated for Deletion and now if users press on the red button and Delete all files plus Document directory delete, it should delete one file at a time not all with directory. Following is the code:

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle 
forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);   
NSString *documentsDirectoryPath = [paths objectAtIndex:0];  

NSMutableString *File = [documentsDirectoryPath stringByAppendingPathComponent:fileNameString];  

NSFileManager *fileManager = [NSFileManager defaultManager];  
[fileManager removeItemAtPath:File error:NULL];  

[self.downList removeObjectAtIndex:indexPath.row];  


[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];  
    }     
}  

I hope some one knows where is the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

八巷 2024-11-08 09:26:14

好吧,我明白了,我想当我按下“删除”按钮时,cell.text.text 将由“didSelectRowAtIndexPath”方法读取,但我错了,所以现在我在以下步骤中实现了代码
1. 当用户选择任何单元格时,将弹出操作表
2.从操作表中用户可以选择“删除”选项
3. 选择“删除”选项后,将执行删除操作并删除特定文件

ok here I figure it out, i thought when i am pressing "Delete" button cell.text.text will be read by "didSelectRowAtIndexPath" method but i am wrong so now i implemented code in following steps
1. as user will select any cell, action sheet will pop out
2. from action sheet user can select "Delete" option
3. on selection of "Delete" option deletion will be performed and particular file will be deleted

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文