views:

14043

answers:

4

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?

+73  A: 

All you have to do is set the selection style on the UITableViewCell instance using either:

cell.selectionStyle = UITableViewCellSelectionStyleNone;

or

[cell setSelectionStyle:UITableViewCellSelectionStyleNone];

Further, make sure you either don't implement -tableView:didSelectRowAtIndexPath: in your table view delegate or explicitly exclude the cells you want to have no action if you do implement it.

More info here and here

Martin Gordon
A: 

You can simply implement -tableView:didSelectRowAtIndexPath: function as return nil;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath does not return a value.
titaniumdecoy
I think you mean willselectRowAtIndexPath
Nathan Reed
A: 

From the UITableViewDelegate Protocol you can use the method willSelectRowAtIndexPath and return nil if you don't want the row selected.

In the same way the you can use the willDeselectRowAtIndexPath method and return nil if you don't want the row to deselect.

I don't like this method because it still shows the cell in its highlighted state until touch up.
Kelso.b
+7  A: 

For me, the following worked fine:

tableView.allowsSelection = NO;

this finally worked for me, I tried to use cell.selectionStyle = UITableViewCellSelectionStyleNone; but it didn't work.One thing to note: it should be: tableView.allowsSelection = NO;not false.
tul697