if (editingStyle == UITableViewCellEditingStyleDelete){
NSFileManager *fileManager = [[NSFileManager alloc]init];
NSString *filePath = [documentsDirectory
stringByAppendingPathComponent:[NSString stringWithFormat:@"%@ ",[self->localSongs objectAtIndex:indexPath.row]]];
[fileManager removeItemAtPath:filePath error:nil];
[self->localSongs removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView reloadData];
}
有什么建议吗?
最佳答案
以下是有关如何从文档目录中删除文件的代码:
NSString *imageName = @"name of your file"
NSFileManager *fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
[fileManager removeItemAtPath:[documentsDirectory stringByAppendingPathComponent:imageName] error:nil];
关于iphone - 使用滑动手势从表 View 中删除文件,而不从文档目录中删除文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/17855318/