tags:

views:

31

answers:

2

i have a UItableview and i want to change the cell background when it is seleceted and keep it like that so i tried to use [cell setBackgroundColor:[UIColor purpleColor]]; but that made other cells get colored at same time and i dont know why i also tried to use [cell.textLabel setBackgroundColor:[UIColor purpleColor]]; but when i select another cell the background go back to white color so any ideas for solving that problem??

+2  A: 

UIView *backgroundView = [[UIView alloc] initWithFrame:cell.selectedBackgroundView.frame];
[backgroundView setBackgroundColor:[UIColor purpleColor]];
[cell setSelectedBackgroundView:backgroundView];
[backgroundView release];

Brainfeeder
the problem is that when i select another cell the previous cell go back to white again and i dont wanna that
Manal
I don't get it. Are you trying to achieve multiselection? If so, AFAIK you have to implement it yourself.
Brainfeeder
A: 

since 3.0, set it in the willDisplayCell method:

 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];

}

Orbit