Ios中的表格单元格颜色

问题描述:

我想更改点击时表格单元格的颜色。当轻拍被释放时,它会达到其初始颜色。我没有应用选择风格。我试图在选择方法中改变颜色,但是在敲击之后它会改变颜色,并且效果是永久性的。Ios中的表格单元格颜色

- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    return YES; 
} 
- (void)tableView:(UITableView *)tableView didHighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    [self setCellColor:[UIColor yellowColor] ForCell:cell]; 
} 
- (void)tableView:(UITableView *)tableView didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath { 
    CustomCell *cell = (CustomCell *)[tableView cellForRowAtIndexPath:indexPath]; 
    [self setCellColor:[UIColor colorWithWhite:1.0 alpha:1.0] ForCell:cell]; 
} 
- (void)setCellColor:(UIColor *)color ForCell:(UITableViewCell *)cell { 
    cell.contentView.backgroundColor = color; 
    cell.backgroundColor = color; 
}