在我的项目中,我只是想在滑动时隐藏单元格。如果我从tableview隐藏单元格撤消按钮将生成我的导航栏顶部。单击撤消按钮,隐藏的单元格应重新出现。
这是我的代码..
-(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
Download *download = [self.downloadManager.downloads objectAtIndex:indexPath.row];
// Get path to documents directory
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
// Get zip file from path..
NSString *fileInDocumentsPath = [documentsPath stringByAppendingPathComponent:download.name];
NSLog(@"Looking for zip file %@", fileInDocumentsPath);
if ([[NSFileManager defaultManager] fileExistsAtPath:fileInDocumentsPath])
{
UITableViewRowAction *HideAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Hide" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
//insert your editAction here
[self.downloadManager.downloads removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
UIBarButtonItem *UndoButton = [[UIBarButtonItem alloc] initWithTitle:@"Undo" style:UIBarButtonItemStyleBordered target:self action:@selector(UndoAction:)];
self.navigationItem.rightBarButtonItem=UndoButton;
}];
HideAction.backgroundColor = [UIColor blueColor];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
//insert your deleteAction here
}];
deleteAction.backgroundColor = [UIColor redColor];
return @[deleteAction,HideAction];
}
else
{
UITableViewRowAction *HideAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Hide" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
//insert your editAction here
}];
HideAction.backgroundColor = [UIColor blueColor];
return @[HideAction];
}
}