Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to switch a UITableViewCell from "normal" view to transparent, and back again
    primarykey
    data
    text
    <p>I have a table view which flips back and forth between view mode and edit mode. I have one cell which I would like to be transparent in view mode, and look like a "normal" cell in edit mode (i.e. white background, rounded rectangle outline). Basically, the same thing you see the name cell do in the contacts app as you switch in &amp; out of edit mode.</p> <p>I used the solution in <a href="https://stackoverflow.com/questions/1008246/how-to-create-a-uitableviewcell-with-a-transparent-background">How to create a UITableViewCell with a transparent background</a> to get a transparent background, but I can't figure out how to get the original background back.</p> <p>Currently, I create two background views in viewDidLoad:</p> <pre><code>nameCellDefaultBackview = [[UIView alloc] initWithFrame:CGRectZero]; nameCellDefaultBackview.backgroundColor = [UIColor clearColor]; nameCellEditBackview = [[UIView alloc] initWithFrame:CGRectZero]; nameCellEditBackview.backgroundColor = [UIColor whiteColor]; </code></pre> <p>I then give my cell the default background view:</p> <pre><code>nameCell.backgroundView = nameCellDefaultBackview; </code></pre> <p>In setEditing:animated: I set the background of the cell depending on the editing mode:</p> <pre><code>if (editing) { nameCell.backgroundView = nameCellEditBackview; } else { nameCell.backgroundView = nameCellDefaultBackview; } </code></pre> <p>The problem is, in editing mode I get a white rectangle instead of something that looks like a cell - which is precisely what I asked for, but not what I want :). I've tried a couple of other things, like setting backgroundView to nil (which seems to = no change), and saving the 'initial' background view in viewDidLoad (that didn't seem to work, and looking in the debugger the variable was 0x0 when I tried to assign it to the cell in setEditing). </p> <p>So what I want is to look like this in normal mode:</p> <p><img src="https://i.stack.imgur.com/iQd1u.png" alt="normal mode"></p> <p>And like this in edit mode:</p> <p><img src="https://i.stack.imgur.com/B5pDo.png" alt="edit mode"></p> <p>But what I <em>currently</em> get in edit mode is:</p> <p><img src="https://i.stack.imgur.com/0G2HB.png" alt="current edit view"></p> <p>So how do I get the white background/border/rounded corners back?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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