开发者

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜