None from the answers above really addresses the issue correctly. The reason is that we want to disable selection of the cell but not necessarily of subviews inside the cell.
In my case I was presenting a UISwitch in the middle of the row and I wanted to disable selection for the rest of the row (which is empty) but not for the switch! The proper way of doing that is hence in the method
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
where a statement of the form
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
disables selection for the specific cell while at the same time allows the user to manipulate the switch and hence use the appropriate selector. This is not true if somebody disables user interaction through the
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method which merely prepares the cell and does not allow interaction with the UISwitch.
Moreover, using the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
in order to deselect the cell with a statement of the form
[tableView deselectRowAtIndexPath:indexPath animated:NO];
still shows the row being selected while the user presses on the original contentView of the cell.
Just my two cents. I am pretty sure many will find this useful.