15

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?

3
  • 2
    possible duplicate of How can I disable the UITableView selection highlighting? Commented Jun 2, 2011 at 14:43
  • 1
    On the plus side, that question has the answer you need :) Commented Jun 2, 2011 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. Commented Sep 1, 2011 at 12:22

8 Answers 8

19

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you very much pratikshabhisikar. I appreciate your quick and correct answer.
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.

Comments

6

Use the UITabelViewCell selectionStyle property.

myCell.selectionStyle = UITableViewCellSelectionStyleNone; 

Comments

3
 tableView.allowsSelection = NO; 

2 Comments

I like your answer and your user name.
The OP specifically said that he needs to allow selection so the cell accessory can be tapped.
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".

Comments

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;

Comments

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

Comments

0

Programtically Default UITableViewCell is UITableViewCellSelectionStyleBlue Change it UITableViewCellSelectionStyleNone.

myCell.selectionStyle = UITableViewCellSelectionStyleNone;

By using StoryBoard

enter image description here

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.