0

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.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Pooja
  • 2,162
  • 5
  • 33
  • 64
  • please put more effort into formatting your code properly. – Mat Apr 15 '11 at 14:35
  • sorry Mat, next time will do, and thanks for formatting code – Pooja Apr 15 '11 at 14:39
  • what is fileNameString? please NSLog(@"File :%@",File) and also self.downList just before and after removal of element. – Ravin Apr 15 '11 at 15:11
  • this contain name of file - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath dequeueReusableCellWithIdentifier:CellIdentifier]; cell = [tableView cellForRowAtIndexPath:indexPath]; fileNameString = [NSString stringWithString:cell.textLabel.text]; } – Pooja Apr 15 '11 at 15:19
  • also downList just an array containing all name of files which are stored in document directory i am using this array to display in cell – Pooja Apr 15 '11 at 15:20

1 Answers1

1

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

Pooja
  • 2,162
  • 5
  • 33
  • 64