How can I set the UITableView's cell property to be unselectable? I don't want to see that blue selection box when the user taps on the cell.
Apple says that the first thing you should do in didSelectRowAtIndexPath is to deselect the row
[tableView deselectRowAtIndexPath:[tableView indexPathForSelectedRow] animated:NO];
Then you can change the AccessoryType to be a checkmark, or none, etc. So when you enter didSelectRowAtIndexPath you could deselect the row, and if its not meant to be selected, simply don't check that row.
To completely prevent selection of the UITableViewCell, have your UITableViewDelegate implement tableView:willSelectRowAtIndexPath:. From that method you can return nil if you do not want the row to be selected.
- (NSIndexPath *)tableView:(UITableView *)tv willSelectRowAtIndexPath:(NSIndexPath *)path
{
// Determine if row is selectable based on the NSIndexPath.
if (rowIsSelectable)
{
return path;
}
return nil;
}
Set the table cell's selectionStyle property to UITableViewCellSelectionStyleNone. That should prevent it from highlighting, and you can also check that property in your tableView:didSelectRowAtIndexPath:.
Had this problem, too, tried everything already mentioned. The final trick, which got rid of the "blue flash" at selecting a table cell was adding this line:
self.myTableView.allowsSelection = NO;
Not sure whether it was this one line or everything combined, but as total grand result I get no more blue selection or even the blue flash. Happy!
use this:
cell.selectionStyle = UITableViewCellSelectionStyleNone;