Container View Receives Touches Instead of Subview on iPad

China☆狼群 提交于 2019-12-11 18:39:24

问题


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!

来源:https://stackoverflow.com/questions/27968238/container-view-receives-touches-instead-of-subview-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!