我有一个 UITableView,其中有从 UIWebView 下载的文件。在我进行更改之前,我可以毫无问题地删除该行以及从它下载到的本地文件夹中。
从那时起,我实现了多选功能。按编辑,选择 w/e 文件,按删除以显示操作表工作正常。但是对于我的生活,我无法弄清楚如何使操作表处理删除操作。
下面我将发布我正在使用的代码。
//viewDidLoad:
self.deleteButton = [[UIBarButtonItem alloc] initWithTitle:@"Delete" style:UIBarButtonItemStyleBordered target:self action:@selector(deleteButton:)];
- (void)deleteButton:(id)sender
{
NSString *actionTitle = ([[self.tableView indexPathsForSelectedRows] count] == 1) ?
@"Are you sure you want to remove this item?" : @"Are you sure you want to remove these items?";
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:actionTitle delegate:self cancelButtonTitle:@"Cancel"
destructiveButtonTitle:@"OK" otherButtonTitles:nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:self.view];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete){
NSString *fileName = [directoryContents objectAtIndex:indexPath.row];
NSString *path;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"downloads"];
path = [path stringByAppendingPathComponent:fileName];
NSError *error;
//Remove cell
[directoryContents removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
//[tableView reloadData];
if ([[NSFileManager defaultManager] fileExistsAtPath:path]) //Does file exist?
{
if (![[NSFileManager defaultManager] removeItemAtPath:path error:&error]) //Delete it
{
NSLog(@"Delete file error: %@", error);
}
}
}
}
任何有关如何链接“确定”按钮以完成删除的信息将不胜感激。