6

I've just created UITableViewCell. I added to it two buttons. Then I set transparent background to the cell.

cell.backgroundView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease];

But there is a problem. When user tapped on cell it changed the color to blue. But I don't want to see any reaction when a user is tapping.

Please see screenshots.

enter image description here

tapped action

enter image description here

Voloda2
  • 12,009
  • 18
  • 78
  • 128
  • 1
    Duplicate entry [http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting][1] [1]: http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting – defvol Nov 14 '11 at 21:18
  • This might be a duplicate entry [http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting][1] [1]: http://stackoverflow.com/questions/190908/how-can-i-disable-the-uitableview-selection-highlighting – defvol Nov 15 '11 at 01:12

4 Answers4

10

Update for Swift 5:

set the selection style to none

    cell.selectionStyle = .none;

Don't use - cell.isUserInteractionEnabled = false Or your buttons won't work.

colin
  • 423
  • 9
  • 18
shannoga
  • 19,316
  • 20
  • 102
  • 165
6

There are a few ways:

1.cell.userInteractionEnabled = NO; (to make cell 'ready-only' - this includes the buttons)

2.cell.selectionStyle = UITableViewCellSelectionStyleNone; (to disable just highlighting)

3.tableView.allowsSelection = NO; (disables just highlighting for whole table)

4.tableView.UserInteractionEnabled:NO; (to make whole table 'ready-only' - including buttons)

Bo A
  • 3,127
  • 2
  • 30
  • 49
0

cell.selectionStyle = UITableViewCellSelectionStyleNone;

0

Swift 4 solution:

// disable selection for a specific cell
cell.selectionStyle = .none

// disable selection for all cells inside your TableView
tableView.allowsSelection = false
budiDino
  • 12,178
  • 8
  • 92
  • 90