如何解决commitEditingStyle并从文档目录删除文件
| 我正在尝试使用commitEditingStyle
方法从文档目录中删除文件,但是我面临以下问题:
在一个表中,我显示了保存在文档目录中的所有文件名。当用户按下\“ Edit \”时,所有单元格都被激活以进行删除,现在如果用户按下红色按钮并单击Delete all files plus Document directory delete,它应该一次删除一个文件,而不是全部删除目录。以下是代码:
- (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];
}
}
我希望有人知道问题出在哪里。
解决方法
好的,在这里我弄清楚了,我想当我按下\“ Delete \”按钮时cell.text.text将被\“ didSelectRowAtIndexPath \”方法读取,但是我错了,所以现在我在以下步骤中实现了代码
1.当用户选择任何单元格时,将弹出操作表
2.从操作表中,用户可以选择\“删除\”选项
3.选择“删除”选项后,将执行删除操作,并将删除特定文件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。