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
2008-10-10 13:22:04
A:
You can simply implement -tableView:didSelectRowAtIndexPath: function as return nil;
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath does not return a value.
titaniumdecoy
2009-06-30 01:49:41
I think you mean willselectRowAtIndexPath
Nathan Reed
2010-10-04 01:43:38
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
2010-02-14 08:25:58
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
2010-05-21 18:26:12