Question

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 ?

Was it helpful?

Solution 2

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;
}

OTHER TIPS

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.)

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;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top