简体   繁体   中英

commitEditingStyle and delete file from document directory

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM