0

I have a UItableview with custom cells in it. The height of the cell changes when you select it and gives an expanding effect. However, when you you select the cell the background of all the subviews become transparent it seems. I've tried setting the cell's SelectedBackgroundView but that doesn't really affect the cells subviews.

Here are some images:

Closed: enter image description here

Open: ![enter image description here][2]

This is how its supposed to look or at least does in XCode - (Sorry for the bad graphic here) enter image description here

jharr100
  • 1,449
  • 24
  • 51

4 Answers4

5

Call [tableView deselectRowAtIndexPath:indexPath animated:YES]; at didSelectRowAtIndexPath. This should solve your issue.

Edit

If you don't want to see any grey selection at all, then, in your cellForRowAtIndexPath, set the cell.selectionStyle to UITableViewCellSelectionStyleNone, like so:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
avismara
  • 5,141
  • 2
  • 32
  • 56
  • This is a solution; however,because of some animations this does not seem to be the best solution. There is like a second or so where the cell shows the colorless part before showing it correctly. – jharr100 Aug 27 '14 at 19:50
  • Then set `tableView deselectRowAtIndexPath:indexPath animated:NO];` – avismara Aug 27 '14 at 19:51
  • DUH ME! I didn't even really think to change that...I actually thought it was because I was calling beginupdates() and endupdates() that that was the reason why but this fixed it – jharr100 Aug 27 '14 at 19:55
2

Presuming that you have subclassed UITableViewCell for your custom cells, you can modify a cell's appearance when selected/deselected by overriding the setSelected method in your custom subclass. For example:

- (void) setSelected:(BOOL)selected {

    [super setSelected:selected];
    if (selected) {
        //Configure the selected state here
    } else {
        //Configure the deselected state here
    } 
}
BFar
  • 2,447
  • 22
  • 23
2

UITableViewCell changes the backgroundColor of all subviews on selection for some reason.

This might help:

DVColorLockView

DylanVann
  • 483
  • 5
  • 9
0

If you want the normal selection behavior but want to exclude specific cell subviews, you can do something like this to lock the background color by subclassing and checking if it is locked in the backgroundColor setter.

zekel
  • 9,227
  • 10
  • 65
  • 96