Reputation: 1484
I'm trying to ignore touches for a certain subviews added to my custom UITableViewCell subclass. I set exclusiveTouch to YES for that subview but the touches still trigger the cell selection. Is there a way to avoid that selection just when touches are in that subiew? Thanks
Upvotes: 1
Views: 641
Reputation: 82227
In my experience, @Ali3n's solution doesn't work (i.e. using view.userInteractionEnabled = NO). When you tap on the view, the cell is still selected.
However, I've found that if you add a UIButton as a subview, and add your subviews to that then it does work as you'd expect - i.e. you tap on the area covered by the button and the cell is not selected. If you use a custom style UIButton then it doesn't look any different to a plain UIView anyway.
Here's how I add a UISwitch to the accessoryView with a non-tappable UIButton behind it. If you miss the button and hit the background the cell is not selected.
UIButton* button =[UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(0, 0, 100, 67);
self.accessoryView = button;
self.accessoryView.backgroundColor = [UIColor grayColor];
UISwitch* statusSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(0, 20, 80, 40)];
[self.accessoryView addSubview:statusSwitch];
Upvotes: 1
Reputation: 1244
you can disable user interation on those views using userInteractionEnabled property of UIView Like :--
view.userInteractionEnabled = NO;
Upvotes: 1