Reputation: 275
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 ?
Upvotes: 4
Views: 4683
Reputation: 1051
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;
}
Upvotes: 1
Reputation: 2044
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:
tableView.allowsSelection
to NO
.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.)
Upvotes: 3
Reputation: 4173
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;
Upvotes: 1