Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView separator line disappears when selecting cells in iOS7

In my tableView I set a separator line between cells. I am allowing selection of multiple cells. Here's my code for setting selected cell background color:

UIView *cellBackgroundColorView = [[UIView alloc] initWithFrame:cell.frame];
[cellBackgroundColorView setBackgroundColor:[UIColor darkGray]];
[cell setSelectedBackgroundView:cellBackgroundColorView];

The problem is that if two adjacent cells are selected, there is no separator line between them in iOS7, while there is (as expected) in iOS6.

I even tried setting cellBackgroundColorView's frame height to that of cell.frame - 1.0, but that doesn't work either.

Any ideas?

like image 205
artooras Avatar asked Oct 06 '13 18:10

artooras


2 Answers

I haven't gotten to the bottom of it yet (at first glance it seems like an iOS 7 bug..), but I have found a workaround. In tableView:didSelectRowAtIndexPath, if you send both messages below, the issue is visually resolved (with the probable performance cost).

[tableView deselectRowAtIndexPath:indexPath animated:YES];
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];

For this to work (for me), deselectRowAtIndexPath:animated: must contain animated:YES. The animation used for reloadRowsAtIndexPaths:withRowAnimation: doesn't matter.

like image 172
Mark Avatar answered Nov 11 '22 18:11

Mark


Add this code at cell for row at indexpath

cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.backgroundColor = [UIColor clearColor];
like image 28
srivatasa Avatar answered Nov 11 '22 19:11

srivatasa