2
votes

I've been trying to stop the (-) delete indicator from showing up when I put a UITableView into editing mode.

Updates for clarity:

This is what the table looks like:enter image description here

This is what I have setup in - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath enter image description here

When I tap reorder, I go into edit mode. I don't want these to show: enter image description here

I've worked around the the 3rd screenshot by limiting the buttons shown from editActionsForRowAtIndexPath to just delete, but I don't even want to get to this part. I want Edit mode to be reorder only enter image description here

/Updates

I've tried setting UITableViewCell.shouldIndentWhileEditing = NO

On the Cell directly:

cell.indentationLevel = -3;
cell.shouldIndentWhileEditing = NO;

In interface builder

In the appropriate delegate method

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
    {
        NSLog(@"shouldIndentWhileEditingRowAtIndexPath");
        return NO;
    }

I'm also showing over items in the actions list. I hadn't planned on having delete at all when in Editing mode, just reodering. I've adjusted a few things so I only show the delete when a user swipes, but I'd rather the (-) not show at all:

- (void) endEditing
{
    self.editMode = NO;
    self.editControlButton.title = @"Reorder";
    [self setEditing:NO animated:YES];
    //[self.tableView reloadData];
}

- (void) startEditing
{
    self.editMode = YES;
    self.editControlButton.title = @"Done";
    [self.tableView setEditing:YES animated:YES];
}

#pragma - mark UITableViewDelegate

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleDelete;
}

- (BOOL)tableView:(UITableView *)tableview shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"shouldIndentWhileEditingRowAtIndexPath");
    return NO;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    TCORead *item = [self.fetchedResultsControllerDataSource selectedItem];
    manager.currentRead = item;
}

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Delete" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
        [self.tableView setEditing:NO];
    }];

    //workaround, rdar://17969970
    //normally don't want to be able to get into this menu when reordering
    if (!self.editMode) {
        UITableViewRowAction *shareAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"Share" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
            [self.tableView setEditing:NO];
        }];
        shareAction.backgroundColor = [UIColor grayColor];

        UITableViewRowAction *doneAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"Done" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath){
            [self.tableView setEditing:NO];
        }];
        doneAction.backgroundColor = [UIColor greenColor];

        [self startEditing];
        return @[deleteAction, doneAction, shareAction];
    }

    return @[deleteAction];
}

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    [self endEditing];
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    //empty on purpose
}
2
What exactly do you want to happen when the tableView goes into editing mode? Why use editing mode at all if you don't want the delete buttons to appear? - dwlz
@Dan Thanks, I've updated the question with screenshots. I'm using edit mode to allow for reordering. But, can handle deletes outside of edit mode - timbroder

2 Answers

2
votes

I was forcing the delete indicator to appear. Vanyas has a sample project that showed me what I was doing wrong.

My editingStyleForRowAtIndexPath method needed to look like this:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:   (NSIndexPath *)indexPath
{
//return UITableViewCellEditingStyleDelete;
return tableView.isEditing ? UITableViewCellEditingStyleNone: UITableViewCellEditingStyleDelete;
}
1
votes

If you don't want to allow deleting, just reordering, then there is no need to do anything about indenting. Instead, just do:

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return UITableViewCellEditingStyleNone;
}

And don't implement the tableView:commitEditingStyle:forRowAtIndexPath: method at all.

You also avoid returning deleteAction from tableView:editActionsForRowAtIndexPath:.

That will prevent row deletion. You can now support reordering as needed.