[英]commitEditingStyle and delete file from document directory
我正在嘗試通過使用commitEditingStyle
方法從文檔目錄中刪除文件,但commitEditingStyle
以下問題:
在一個表中,我顯示了保存在文檔目錄中的所有文件名。 當用戶按下“編輯”時,將激活所有單元格以進行刪除,現在,如果用戶按下紅色按鈕並單擊“刪除所有文件和文檔目錄”,則它應一次刪除一個文件,而不是全部刪除目錄。 以下是代碼:
- (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.選擇“刪除”選項后,將執行刪除操作,並將刪除特定文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.