我想在敲击时更改表格单元格的颜色。松开龙头时,它将恢复到初始颜色。我没有应用选择样式。我试着用选择的方法改变颜色,但它在敲击后会改变颜色,效果是永久的。
- (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;
}