Reputation: 131
I want to change the colour of table cell on tapping. It will get to its initial colour when tap is release. I have applied selection style none. I have tried to change the colour in did select method but it is changing colour after tapping and effects are permanent.
Upvotes: 0
Views: 38
Reputation: 35963
- (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;
}
Upvotes: 1