Cells not getting selected in UITableView with allowsMultipleSelectionDuringEditing set in edit mode
Asked Answered
P

4

8

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.

Perfectionist answered 3/10, 2012 at 12:8 Comment(0)
P
31

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.

Perfectionist answered 3/10, 2012 at 14:5 Comment(1)
Thanks from 2018. Finally found this answer and fixed my problem!Thirteenth
V
1

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.

Vacuva answered 12/2, 2014 at 10:5 Comment(1)
Thanks from 2020. I had a similar issue: my custom UITableViewCell was not calling [super setEditing:animated].Rsfsr
M
1

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;
Maryannmaryanna answered 26/2, 2014 at 20:13 Comment(0)
G
0

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;
}
Grafting answered 5/6, 2014 at 8:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.