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
2010-10-28 12:51:29
the problem is that when i select another cell the previous cell go back to white again and i dont wanna that
Manal
2010-10-30 18:39:52
I don't get it. Are you trying to achieve multiselection? If so, AFAIK you have to implement it yourself.
Brainfeeder
2010-10-30 20:04:10
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
2010-10-28 12:53:27