Container View Receives Touches Instead of Subview

2019-09-10 06:55发布

I have a problem concerning getting a UITableViewController inside of a UIView to get touches in iOS8 (it worked fine in iOS7).

Here's the setup code:

UITableViewController *tvc = [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];
tvc.tableView.userInteractionEnabled = YES;
tvc.tableView.frame = CGRectMake(0, 0, self.incentivesContainerView.frame.size.width, self.incentivesContainerView.frame.size.height);
[self addChildViewController:tvc];
self.incentivesContainerView.clipsToBounds = YES;
[self.incentivesContainerView addSubview:tvc.view];

I have the data source and delegate set up and everything is working fine with the data. The problem is that the incentivesContainerView seems to be blocking touches to the UITableViewController. I have a workaround for the problem that adds a gesture recognizer to the container:

[self.incentivesContainerView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tappedSelectIncentivesView:)]];

Which calls:

- (void)tappedSelectIncentivesView:(UITapGestureRecognizer *)tap {
    CGPoint tapSpot = [tap locationInView:self.selectIncentivesVC.tableView];
    [self.selectIncentivesVC tableView:self.selectIncentivesVC.tableView didSelectRowAtIndexPath:[self.selectIncentivesVC.tableView indexPathForRowAtPoint:tapSpot]];
}

which passes on the touch events and works fine.

However, I'd like a cleaner approach if possible, is there a better way to be doing this?

I found this post, which looks like my problem, but I'd really rather not subclass UIView either: How to Make Touch Events Affect View's Behind a Container View?

I found a few other posts on SO that looked similar but didn't quite work for me, any suggestions?

Thanks!

0条回答
登录 后发表回答