0

I am trying to have an UIimageview's image change to it's highlighted image when the cell it is in is selected. The problem is that I do not want the cell's background color to change when it is selected. I tried overriding the coloring by using.

cell.selectedBackgroundView.backgroundColor = [UIColor clearColor];

However, this had no effect. I do not want to set the cell's selectiontype to None because then the cell cannot be selected/highlighted so the cell's imageview is never switched to highlighted state.

Please let me know how I can control the background color of a selected cell and override the color change.

Josh Wang
  • 315
  • 1
  • 4
  • 10
  • You can create subclass of UITableViewCell and override - (void)setSelected:(BOOL)selected animated:(BOOL)animated method, and do in it every you whant – BergP Oct 07 '13 at 20:32

2 Answers2

0

You can create subclass of UITableViewCell, and override - (void)setSelected:(BOOL)selected animated:(BOOL)animated method, it gives you really flexible ability to custom your selection

also you can see https://developer.apple.com/library/ios/documentation/userexperience/conceptual/TableView_iPhone/TableViewCells/TableViewCells.html

Custom UITableViewCell and animation on setSelected:animated:

Changing elements in selected UITableViewCell subclass

UITableViewCell subclass

Community
  • 1
  • 1
BergP
  • 3,453
  • 4
  • 33
  • 58
0

With UITableViewCellSelectionStyleNone, you can still use -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath. It will be called even though there's no visible indication on screen.

jsd
  • 7,673
  • 5
  • 27
  • 47
  • I think that encapsulate UITableViewCell related logic in UITableViewCell subclass will be better. Am I wrong? It seems like every cell has its own UIImageView – BergP Oct 07 '13 at 20:43
  • but at the end of the call all highlighted statuses for things inside the cell are set to NO – Josh Wang Oct 07 '13 at 20:52
  • @PavelKatunin you're not wrong. But in didSelectRowAtIndexPath, you can get the cell by using cellForRowAtIndexPath and then call methods on that if you want. – jsd Oct 08 '13 at 16:35