4

I want to disable cell interaction. In my function:

- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

I added

Cell.userInteractionEnabled = NO;

And cell interaction is disabled, but I want to leave active button (ButtonLabel).

Cell.userInteractionEnabled = NO;
Cell.ButtonLabel.userInteractionEnabled = YES;

The above code does not work. It is strange, because inversly is ok:

Cell.userInteractionEnabled = YES;
Cell.ButtonLabel.userInteractionEnabled = NO;

Button is disabled but cell no.

How to make my button active while cell is disabled ?

Amar
  • 13,202
  • 7
  • 53
  • 71
Nizzre
  • 275
  • 1
  • 6
  • 14
  • 1
    Set the ``[Cell setSelectionStyle:UITableViewCellSelectionStyleNone];`` – kaar3k Oct 24 '13 at 08:49
  • 1
    This is because if you disable user interaction for a view all its subviews will also be disabled. – Pratyusha Terli Oct 24 '13 at 08:50
  • I use `Cell.userInteractionEnabled = NO;` because for some cells I have to disable **push** to other view. Is any method to disable only push connection for specific cells? – Nizzre Oct 24 '13 at 08:57

3 Answers3

3

When you set userInteractionEnabled to NO on any instance of UIView (or its subclasses), it automatically disables user interaction on all its subviews. This is exactly the behaviour that you described.

I think what you want to do is to disable selection on a UITableViewCell. There are several ways to do it:

  1. If you want to prevent selection on all cells altogether, you can just set tableView.allowsSelection to NO.
  2. If you want to prevent selection on certain cells only, do Cell.selectionStyle = UITableViewCellSelectionStyleNone;

And you can also override - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath; and return nil for cells that shouldn't trigger selection action (but this alone won't prevent the selection highlight from appearing.)

ivanmoskalev
  • 2,004
  • 1
  • 16
  • 25
  • As i worote below, I need to disable push connection to other view. Is any method to disable only push connection for specific cells? – Nizzre Oct 24 '13 at 09:06
1

If you disable interaction on the cell this will affect all cell elements. What you want to do instead is set the cell to UITableViewCellSelectionStyleNone

This will work

 [Cell setSelectionStyle:UITableViewCellSelectionStyleNone];
Cell.ButtonLabel.userInteractionEnabled = YES;
Jonathan Thurft
  • 4,087
  • 7
  • 47
  • 78
1

According to your comment, you want do disable push connection for specific cell. What you can do is check in shoudlPerformSegueWithIdentifier if that cell should perform.

You need to save which was the cell touched, and then:

-(BOOL)shouldPerformSegueWithIdentifier:(NSString *)identifier sender:(id)sender
{
    if (/*check if the selected cell should perform the segue*/) {
        return YES;
    }

    return NO;
}
Alex
  • 1,061
  • 10
  • 14