在iOS中滚动后如何调整tableview的单元格颜色

在iOS中滚动后如何调整tableview的单元格颜色,ios,uitableview,colors,Ios,Uitableview,Colors,我正在更改自定义tableView按钮颜色上的单元格颜色。单元格索引行在单击按钮时变为绿色,但在滚动后,它再次变为正常的白色。我尝试了不同的解决方案,但没有结果。你能建议一下吗。谢谢 -(void)yesAction:(id)sender { _cellButtonPress = YES; // [myChklist reloadData]; UIButton *button = (UIButton *)sender; UITableViewCell *cell = (UITableViewC

我正在更改自定义tableView按钮颜色上的单元格颜色。单元格索引行在单击按钮时变为绿色,但在滚动后,它再次变为正常的白色。我尝试了不同的解决方案,但没有结果。你能建议一下吗。谢谢

-(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];
}

当您的单元格滚动时,它会再次被绘制。您需要重新设置属性

您可以维护选定索引的数组。然后,在cellForRowAtIndexPath委托方法中,您可以根据索引将背景颜色设置为白色或绿色。类似于:

  NSMutableArray* indexArray = [[NSMutableArray alloc] init];
在这方面:

 [indexArray addObject:indexPath];
在cellForRowAtIndexPath中:

 if ([indexArray containsObject:indexPath]) {
    cell.backgroundColor = [UIColor greenColor];
}

是的,gr8。我还将此方法放在-(void)tableView:(UITableView*)tableView willDisplayCell:(UITableViewCell*)单元格下,用于rowatinexpath:(nsindepath*)indepath