views:

42

answers:

2

In my normal tableview I got a bunch of switches and segments, and I dont wont them to be selectable, so I set:

tableView.allowsSelection = FALSE;

Now one of the cells, I wont to point to a new view, and thereby make it selectable. But there's no cell.allowSelection or anything, how do I solve this. How do I make it, so that it can be pushed and direct you to another view. I dont wont them all to be selectable, since thats ugly...

A: 

Set cell.userInteractionEnabled = NO; on the cells that are not supposed to be selectable.

Whenever you want to change this, call [tableView reloadData];.

Emil
-1. -reloadData is a bit of a sledgehammer...
tc.
And it is also the only way...
Emil
+2  A: 

There is not an allowsSelection property on cells, but there is a similiar property.

Set cell.selectionStyle to UITableViewCellSelectionStyleNone for cells you don't want to the user to be able to select.

(You will have to set table.allowsSelection back to YES.)

Configured this way, you'll still get -tableView:didSelectRowAtIndexPath: for any cell the user taps; just ignore it for cells that you don't intend to be selectable. (Thanks tc.)

Steven Fisher
The user *can* select those cells (you still get -tableView:didSelectRowAtIndexPath:); it's just not visible.
tc.
Yes, you just ignore those selections. If the selection doesn't appear and doesn't do anything, it might as well not be there. I'll add a note about that, though. :)
Steven Fisher
Works like a charm. And thanks tc, for pointing out the fact that the delegate gets called anyway...
John Kofod