How to prevent UITableView from reserving space at the left of cell when editing is turned on?

By | January 12, 2018
Questions:

I’m set editing mode for UITableView to have a possibility of cell reordering. UITableViewCellEditingStyleNone is returned by editingStyleForRowAtIndexPath: method for every cell, but it reserve some area on the left of cell. Is it possible to prevent such an area reserving, because I’m not need an insert or delete icon on left? In short, i want have a cell that occupate all available area and still can be reordered.

Answers:

See the docs: You can set a boolean on the cell to make it not indent. Just add

cell.shouldIndentWhileEditing = NO;

to wherever you create your cell.

Questions:
Answers:

// UITableViewDelegate

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

Questions:
Answers:

Set this to like 2 or 3

tableView:indentationLevelForRowAtIndexPath:

Questions:
Answers:

The shouldIndentWhileEditing property only works with grouped tables. I found that setting an indentation level of -3 does the job for plain tables. Is there a better way? Here’s what I’m using now:

    if (self.tableView.style == UITableViewStylePlain) {
        cell.indentationLevel = -3;
    } else if (self.tableView.style == UITableViewStyleGrouped) {
        cell.shouldIndentWhileEditing = FALSE;
    }

Questions:
Answers:

Do both

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

and

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

in your UITableViewDelegate. Otherwise the cell content is indented.

Leave a Reply

Your email address will not be published. Required fields are marked *