0

So this problem is pretty weird and a little difficult to describe. Essentially I have a UITableView where each cell has an image, and a UIView covering part of the image. The UIView has it's background colour set to about 30% transparent white, giving it the appearance of washing out the image beneath. There's also some labels and such on it. All these views are added to a single parent container view, which is finally added to the cell's contentView. This all works fine - until I try to select the cell. For some reason, whenever the cell is highlighted, the backgroundColor property on each and every one of those views is set to clear, until the cell is unhighlighted (at which point the old colour returns).

Can anyone explain why this happens, and more important if there's a way to fix it? At most I could create a single pixel image of white, turn the UIView into a UIImageView, and set it's image to that pixel - but that's inelegant at best. Any suggestions?

Xono
  • 1,900
  • 17
  • 20
  • please post some code of tableview didSelect and cellForRowAtIndexPath methods. – Ahmed Z. Jul 18 '13 at 03:00
  • 1
    Check http://stackoverflow.com/questions/5222736/uiview-backgroundcolor-disappears-when-uitableviewcell-is-selected for some options that may help. – Jake Spencer Jul 18 '13 at 03:16
  • Try [this](http://stackoverflow.com/questions/6417590/how-to-disable-highlight-subviews-message-for-uiview-uiviewcontroller-in-ios-s), replacing "_updateHighlightColorsForView" for "_setOpaque". – Timothy Moose Jul 18 '13 at 03:20
  • I'm not getting a clear picture about your problem, even then, try and set the background color of your UIView in the method [UITableViewDelegate willDisplayCell:forRowAtIndexPath:]; – JohnVanDijk Jul 18 '13 at 04:14

1 Answers1

0

When you select the cell, the implementation of setSelected:animated: is called and set the background color of all the views included in this cell to transparent.

Simply, you can just disable the selection of the cell by setting its selectionStyle to None:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

Or, if you want to use the result of selection, you can override the setSelected:animated: method and reset the background color of your UIView

MattZ
  • 381
  • 3
  • 7