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?
-
2possible 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
-
1On the plus side, that question has the answer you need `:)` – e.James Jun 02 '11 at 14:43
-
1Also, 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 Answers
By default, the selectionStyle
property of cell is UITableViewCellSelectionStyleBlue
. Change it to UITableViewCellSelectionStyleNone
.
-
Thank you very much pratikshabhisikar. I appreciate your quick and correct answer. – Jackelope11 Jun 02 '11 at 14:45
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.

- 54,048
- 11
- 129
- 129
Use the UITabelViewCell selectionStyle
property.
myCell.selectionStyle = UITableViewCellSelectionStyleNone;

- 31,697
- 9
- 72
- 76
tableView.allowsSelection = NO;

- 12,145
- 12
- 79
- 132
-
-
The OP specifically said that he needs to allow selection so the cell accessory can be tapped. – mbm29414 Sep 01 '11 at 12:25
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;

- 5,525
- 1
- 40
- 34
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".

- 4,461
- 2
- 30
- 46
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.

- 1,787
- 2
- 23
- 30
Programtically Default UITableViewCell is UITableViewCellSelectionStyleBlue Change it UITableViewCellSelectionStyleNone.
myCell.selectionStyle = UITableViewCellSelectionStyleNone;
By using StoryBoard

- 91
- 1
- 7