Does anyone know how to change the background color of a cell using UITableViewCell, for each selected cell? I created this UITableViewCell inside the code for TableView.
I was able to solve this problem by creating a subclass of UITableViewCell and implementing the setSelected:animated: method
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
if(selected) {
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
[self setBackgroundColor:[UIColor greenColor]];
} else {
[self setBackgroundColor:[UIColor whiteColor]];
}
}
The trick was setting the
cell.selectionStyle = UITableViewCellSelectionStyleDefault;
in the implementing view controller and then in the tableViewCell setting it as
[self setSelectionStyle:UITableViewCellSelectionStyleNone];
Hope this helps. :)