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];
}
要實現使用滑動手勢從TableView刪除文件,不從文件目錄中
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];