16

I am using a UITableView and the cells I am using in this view should do nothing when I click them. I can't turn off UserInteraction though because then I am not able to click on the accessory (detailDisclosureButton). So how can I make them stop turning blue and still allow them to click on the accessory?

Jackelope11
  • 1,181
  • 4
  • 15
  • 31
  • 2
    possible duplicate of [How can I disable the UITableView selection highlighting?](http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting) – e.James Jun 02 '11 at 14:43
  • 1
    On the plus side, that question has the answer you need `:)` – e.James Jun 02 '11 at 14:43
  • 1
    Also, don't forget that that answer below doesn't prevent `tableView:didSelectRowAtIndexPath:` from firing. Just because you won't SEE the selection doesn't mean it won't HAPPEN. I say this just to remind you to handle for that in the method I mentioned above. – mbm29414 Sep 01 '11 at 12:22

8 Answers8

19

By default, the selectionStyle property of cell is UITableViewCellSelectionStyleBlue. Change it to UITableViewCellSelectionStyleNone.

10

When you're generating the UITableViewCell (within the UITableView's - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath method call), simply set the selectionStyle property to UITableViewCellSelectionStyleNone.

Set the UITableViewCell Class Reference for more information.

John Parker
  • 54,048
  • 11
  • 129
  • 129
6

Use the UITabelViewCell selectionStyle property.

myCell.selectionStyle = UITableViewCellSelectionStyleNone;
Jhaliya - Praveen Sharma
  • 31,697
  • 9
  • 72
  • 76
3
 tableView.allowsSelection = NO;
Legolas
  • 12,145
  • 12
  • 79
  • 132
2

If you want use to select cell add below code in method viewDidLoad

self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

moreover you can disable selection overall for your whole table by adding:

self.tableView.allowsSelection = NO;

Ash
  • 5,525
  • 1
  • 40
  • 34
2

You can do this by adding the selection style to none or gray. By default it is blue.

cell.selectionStyle = UITableViewCellSelectionStyleNone; cell.selectionStyle = UITableViewCellSelectionStyleGray;

You need to write this code in the method "- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath".

AppAspect
  • 4,461
  • 2
  • 30
  • 46
1

It can easily done by StoryBoard without writing one line of code. In your UITableViewCell's XIB in Attribute Inspector set value of Selection to Gray or None to stop a cell turning blue on selection and it still be selectable.

enter image description here

0

Programtically Default UITableViewCell is UITableViewCellSelectionStyleBlue Change it UITableViewCellSelectionStyleNone.

myCell.selectionStyle = UITableViewCellSelectionStyleNone;

By using StoryBoard

enter image description here

testing
  • 91
  • 1
  • 7