4

Possible Duplicate:
How can I disable the UITableView selection highlighting?

When you tap a row in a UITableView, the row is highlighted and selected. Is it possible to disable this so tapping a row does nothing?

Community
  • 1
  • 1
  • In the dup article, I prefer the lower-vote answer that sets the allowsSelection=NO on property on the tableView. – danh Jan 10 '13 at 16:48
  • Setting `allowsSelection` to `NO` is good, but only if you want the entire table view to have unselectable rows. For more fine-grain control over individual cells' selectability, use `UITableViewCell`'s `selectionStyle` property instead. – Pripyat Jan 10 '13 at 17:20
  • In 2020, look here: https://stackoverflow.com/a/64582629/171933 – Johannes Fahrenkrug Oct 28 '20 at 23:10

4 Answers4

4

Yes below code will disable user interaction , if you jut want to disable some certain cells you need to write some if - else methods

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    cell.userInteractionEnabled = NO;

    return cell;
}
user427969
  • 3,828
  • 4
  • 46
  • 73
u.gen
  • 4,680
  • 4
  • 41
  • 77
1

If you have buttons or anything on your cell that still needs to be 'touchable', than just set the selection style to none:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

If it just a cell with text than you can do like Space Dust suggested.

RyanG
  • 4,233
  • 1
  • 38
  • 62
1

This has been answered before.

Grab the UITableViewCell instance and set the following property:

cell.selectionStyle = UITableViewCellSelectionStyleNone;
Community
  • 1
  • 1
Pripyat
  • 2,909
  • 2
  • 33
  • 68
1

Also you can try this:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];

    //do ur stuff

}
Satish Azad
  • 2,273
  • 1
  • 15
  • 35