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 have a highly customized UITableViewCell. So I implemented my own cell selection.
cell.selectionStyle = UITableViewCellSelectionStyleNone;
I created a method in my cell's class:
- (void)highlightCell:(BOOL)highlight
{
if (highlight) {
self.contentView.backgroundColor = RGB(0x355881);
_bodyLabel.textColor = RGB(0xffffff);
_fromLabel.textColor = RGB(0xffffff);
_subjectLabel.textColor = RGB(0xffffff);
_dateLabel.textColor = RGB(0xffffff);
}
else {
self.contentView.backgroundColor = RGB(0xf7f7f7);;
_bodyLabel.textColor = RGB(0xaaaaaa);
_fromLabel.textColor = [UIColor blackColor];
_subjectLabel.textColor = [UIColor blackColor];
_dateLabel.textColor = RGB(0x496487);
}
}
In my UITableViewController class in ViewWillAppear added this:
NSIndexPath *tableSelection = [self.tableView indexPathForSelectedRow];
SideSwipeTableViewCell *cell = (SideSwipeTableViewCell*)[self.tableView cellForRowAtIndexPath:tableSelection];
[cell highlightCell:NO];
In didSelectRow added this:
SideSwipeTableViewCell *cell = (SideSwipeTableViewCell*)[self.tableView cellForRowAtIndexPath:indexPath];
[cell highlightCell:YES];