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 & out of edit mode.
I used the solution in How to create a UITableViewCell with a transparent background to get a transparent background, but I can't figure out how to get the original background back.
Currently, I create two background views in viewDidLoad:
nameCellDefaultBackview = [[UIView alloc] initWithFrame:CGRectZero];
nameCellDefaultBackview.backgroundColor = [UIColor clearColor];
nameCellEditBackview = [[UIView alloc] initWithFrame:CGRectZero];
nameCellEditBackview.backgroundColor = [UIColor whiteColor];
I then give my cell the default background view:
nameCell.backgroundView = nameCellDefaultBackview;
In setEditing:animated: I set the background of the cell depending on the editing mode:
if (editing) {
nameCell.backgroundView = nameCellEditBackview;
} else {
nameCell.backgroundView = nameCellDefaultBackview;
}
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).
So what I want is to look like this in normal mode:
And like this in edit mode:
But what I currently get in edit mode is:
So how do I get the white background/border/rounded corners back?