views:

72

answers:

2

On OS 3.0, when allowsSelection = NO, it's not possible to select any row and it also cancels row highlighting.

On pre OS 3.0, the most obvious solution to disallow selection is to return nil in willSelectRowAtIndexPath, which is part of UITableViewDelegate

However, there are two problems with this approach:

1) It's not stable (i.e. from time to time a row do get selected...)
2) It is not canceling row highlighting

Any clue?

+4  A: 

You should set the selectionStyle on the individual UITableViewCells that you don't want to be selectable to UITableViewCellSelectionStyleNone. For those you do want selectable, UITableViewCellSelectionStyleBlue. Essentially:

- (UITableViewCell *)cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //...
    cell.selectionStyle = (canSelectRow ? UITableViewCellSelectionStyleBlue : UITableViewCellSelectionStyleNone);
    return cell;
}
Ed Marty
+1  A: 

To cancel row highlighting you can set cell's selectionStyle to UITableViewCellSelectionStyleNone.

Returning nil from willSelectRowAtIndexPath has always worked for me...

Vladimir