启用所有单元格删除按钮而不滑动手势

时间:2013-08-19 12:18:51

标签: ios uitableview

我想使用核心数据实现UITableView,当我在ViewController中按下“废纸篓”按钮时,我可以看到所有单元格右侧的所有删除按钮,而无需滑动手势。但是当我启用编辑模式时,只需要在右侧显示删除按钮

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSManagedObjectContext *context = [self managedObjectContext];

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete object from database
        [context deleteObject:[self.notes objectAtIndex:indexPath.row]];


        NSError *error = nil;
        if (![context save:&error]) {
            NSLog(@"Can't Delete! %@ %@", error, [error localizedDescription]);
            return;
        }

        // Remove note from table view
        [self.notes removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }
}

任何人都可以建议我怎么可能

1 个答案:

答案 0 :(得分:0)

已编辑: 写下面的代码:

-(void) yourMethodName:(UIButton *) sender
{
       if(self.editing)
        {
            [super setEditing:NO animated:NO];
            [self.tblView setEditing:NO animated:NO];
            [self.tblView reloadData];

        }
        else
        {
            [super setEditing:YES animated:YES];
            [self.tblView setEditing:YES animated:YES];
            [self.tblView reloadData];

        }
}