Cells not getting selected in UITableView with allowsMultipleSelectionDuringEditing set in edit mode

StackOverflow https://stackoverflow.com//questions/12708186

Question

I have a UITableView that is configured to allow multiple cells to be selected in edit mode. However, the empty white circles on the left never change to red circles with the white checkmarks inside after a cell is touched/selected.

I have read about the swipe to delete issue with allowsMultipleSelectionDuringEditing, so my setEditing:animinated method looks like this:

- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    self.tableView.allowsMultipleSelectionDuringEditing = editing;
    [super setEditing:editing animated:animated];
}

Some resources on the Net suggest setting allowsSelectionDuringEditing = NO;, but that has no effect. Also, my cell editing style is set to UITableViewCellEditingStyleDelete, and changing it does not have any effect either.

When a row is touched in edit mode, tableView:didSelectRowForIndexpath: is triggered, but as mentioned above, the UI does not reflect this.

Was it helpful?

Solution

It was, as tends to be the case, my mistake.

The problem was in my implementation of tableView:cellForRowAtIndexPath:, where I was setting the cell's selectionStyle property to UITableViewCellSelectionStyleNone. For some reason, this has the added 'benefit' of disabling the red checkmark on the left hand side in multiselection edit mode.

Setting cell.selectionStyle = UITableViewCellSelectionStyleGray; fixed the issue.

OTHER TIPS

I had a similar problem, because I was working very hard to make sure my cells never showed any selection (for a "chat bubble" style of table).

So of course this fix resulted in great big color bars on my table, and I had to find another way to get rid of them.

In your cellForRowAtIndexPath, you can set a selectedBackgroundView instead of setting the selectionStyle, and it will also enable checkboxes. The view can be your cell's background color, or clearColor, and then nothing will show up. Here's my code:

static dispatch_once_t onceToken;
static UIView * selectedBackgroundView;
dispatch_once(&onceToken, ^{
    selectedBackgroundView = [[UIView alloc] initWithFrame:cell.frame];
    selectedBackgroundView.backgroundColor = APP_CELL_BACKGROUND_COLOR;
});
cell.selectedBackgroundView = selectedBackgroundView;

Old thread but i also had this issue, however i found the cause to be my custom cell was overriding the setSelected and setHighlighted methods without call super.

This resulted in the cells not becoming selectable.

I had the same problem. Ensure that tableView:shouldHighlightRowAtIndexPath: returns YES, otherwise selection will not occur, at least in iOS 7.

- (BOOL)tableView:(UITableView *)tableView
    shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top