In my application, I have a tableView, I changed the background color of cell when it is selected, I wrote that code as
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
cell.backgroundColor = [UIColor whiteColor];
}
The problem is When I scrolled the tableView, the background color of cell is disabled, the white color is not visible means the background color effect is removed. The table view reused the cell when scrolled out so the cell background effect is removed. I know where I get the problem but I don't know how to handle this problem and keep the background color of selected cell as white even the table view is scrolled. Please tell me solution for this problem.
The best way to change the background of selected rows would be to change the
selectedBackgorundView
when you create the cell. That way, you wouldn't need to handledidSelectRowAtIndexPath: