1

我想实现一个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];
    }
}

谁能建议我怎么可能

4

1 回答 1

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];

        }
}
于 2013-08-19T12:22:28.940 回答