Note that there are some explanatory texts on larger screens.

plurals
  1. POUITableViewCell: How to prevent blue selection background w/o borking isSelected property?
    text
    copied!<p>I have a custom <code>UITableViewCell</code> subclass. I have set the <code>contentView</code> of my cell subclass to a custom <code>UIView</code> class in which i am overriding <code>-drawRect:</code> and doing all of the drawing there. </p> <p>Also, I am setting <code>cell.contentView.opaque = NO</code> in order to achieve transparency in certain areas of the cell (unfortunately, a backgroud image behind the table must show thru each cell in certain parts to achieve a stylistic effect. i know this is a performance hit. it must be so).</p> <p>Problem: I still see the default pretty blue gradient background being drawn behind my cell (in the transparent areas) when it is selected or highlighted (being pressed). This is obscuring the image behind the table, which is bad.</p> <p>Goal: To prevent the blue gradient background from appearing, but still be able to inspect the <code>cell.isSelected</code> and <code>cell.isHighlighted</code> properties from within <code>-[MyContentView drawRect:]</code> to determine how to draw my own custom selection/highlighting.</p> <p>What I've tried: </p> <ol> <li><p>setting <code>cell.selectionStyle = UITableViewCellSelectionStyleNone</code> has the desired effect of preventing the pretty blue gradient selection background, but also prevents the <code>cell.isSelected</code> and <code>cell.isHighlighted</code> properties from being properly set, which means i cannot do my own custom selection/highlight drawing</p></li> <li><p>setting <code>cell.selectionBackgroundView = nil</code> and <code>cell.backgroundView = nil</code> in the cell's <code>-init</code> or <code>-prepareForReuse</code> method does not prevent the blue gradient selection background</p></li> <li><p>setting <code>cell.selectionBackgroundView = nil</code> in the <code>-[MyContentView -drawRect:]</code> method <em>does</em> have the desired effect of preventing the blue gradient selection background, but that seems very janky</p></li> <li><p>overriding -[UITableViewCell setSelected:animated:] to be a no-op. this does not have the desired effect of preventing the blue gradient selection background</p></li> </ol>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload