tags:

views:

292

answers:

1

Hello,

Iam creating a custom TableView Cell Which has some text and a Background image. when i select the cell then the image should chnage but this is not hapening, i have use following code so some one help me?

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

 [super setSelected:selected animated:animated];

 if (selected)
  [self.imgSelected setImage:[UIImage imageNamed:@"listing-gradient-hover.png"]];//Image that i want on Selection
 else
  [self.imgSelected setImage:[UIImage imageNamed:@"listing-gradient.png"]];
 //Normal image at background everytime table loads.

    // Configure the view for the selected state

}

This is not working for me.

+2  A: 

Try the following:

initialize an UIImageView to be the background view and an UIImageView to be the selected background view when you setup ypu custom table view cell:

self.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"listing-gradient-hover.png"]];
self.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"listing-gradient.png"]];

UITableViewCell adds the value of the selectedBackgroundView property as a subview only when the cell is selected. It adds the selected background view as a subview directly above the background view (backgroundView) if it is not nil, or behind all other views. Calling setSelected:animated: causes the selected background view to animate in and out with an alpha fade. You do not need to override this method just for switching the background image upon selection.

unforgiven