views:

535

answers:

2

Hi

I've a table view with a custom image background of each cell. In normal mode the background is perfect and fill all the cell. When tableView enter in editing mode the "-" button appear on left and all the object are indented and in the left I've problem with background: there a white area. Can anyone help me? The background image is big enough to fill all the cell but its moved in editing mode. Can I solve it? thanks a lot!

Update:

I used this code in my UITableViewCell subclass:

- (void) layoutSubviews
{

     UIImage *backgroundImage = [UIImage imageNamed:@"sfondoCella2.png"];
     UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.bounds];
     bgView.image = backgroundImage;
     self.backgroundView = bgView;
     [bgView release];

}

To set background and appranetly works well in normal mode but when you go in editing mode all goes wrong: the circulare red delete button not appear and the indentetion of the cell (perfect with the background setted in IB) are not correct.

A: 

You probably added you image view as a subview of the contentView of the UITableViewCell. You need to set your image view as the backgroundView of the UITableViewCell.

The backgroundView doesn't move in edditing mode.

gcamp
I've added it in Interface Builder as background. I think that ita the same
Luca
+1  A: 

I don't think that there is a way to add a background image through IB. Instead, I am assuming you are just adding a UIImage subview.

I've added background images to table cells in code and I don't have the problem that you describe.

UIImage *backgroundImage = [UIImage imageNamed:@"my-bg.png"];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.backgroundView.frame];
bgView.image = backgroundImage;
cell.backgroundView = bgView;
[bgView release];

Ideally you can do this in a custom UITableViewCell's layoutSubviews method and then tell IB that that is the class for your cell.

By extending UITableViewCell you have the ability to override the following methods and have control over exactly how the cell should look when in edit mode or selected.

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
Randy Simon
The Problem is that I want to have 2 different background when cell i selected. In IB if you set Background and Selected Background propriety you can change background when you tap on your cell. With your method the selected background image not works when you tap on cell
Luca
Actually, if you implement your own UITableViewCell you can override setHighlighted and/or setEditing.
Randy Simon