Reputation: 273
I am changing cell colours on custom tableView button colour. Cell indexRow getting green on button click but after scrolling it is again comes to normal white colour. I tried different solutions but no result. Could you pls suggest. Thanks.
-(void)yesAction:(id)sender
{
_cellButtonPress = YES;
// [myChklist reloadData];
UIButton *button = (UIButton *)sender;
UITableViewCell *cell = (UITableViewCell *)button.superview.superview;
UITableView *curTableView = (UITableView *)cell.superview;
NSIndexPath *indexPath = [curTableView indexPathForCell:cell];
cell.backgroundColor = [UIColor greenColor];
}
Upvotes: 0
Views: 651
Reputation: 1043
When your cell scrolls it gets drawn again. You need to set the property again.
You can maintain an array of selected indexes.Then in your cellForRowAtIndexPath delegate method you can set the background color as white or green based on index.Something like:
NSMutableArray* indexArray = [[NSMutableArray alloc] init];
In yesAction :
[indexArray addObject:indexPath];
In cellForRowAtIndexPath:
if ([indexArray containsObject:indexPath]) {
cell.backgroundColor = [UIColor greenColor];
}
Upvotes: 1