0

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!

Community
  • 1
  • 1
Alex
  • 3,861
  • 5
  • 28
  • 44
  • I would say to not create the table view controller or not add that call to add its tableview to the containers subviews. it looks like you're adding the tableviewcontroller with the size of the screen, then assigning its view to the subview of the container view.. which is actually below the tableviewcontroller, which obscures your touches. (ps damn mobile app) – Louis Tur Jan 15 '15 at 17:13
  • Do you have `self.incentivesContainerView.userInteractionEnabled` set to `YES`? If this is set to `NO`, then it blocks all touches to subviews. – Jeffery Thomas Jan 15 '15 at 18:01
  • yeah, it's set to YES – Alex Jan 15 '15 at 18:27
  • Dang, I was using UIView's in the storyboard instead of Container View's, switched them to Container View's and it's working fine. Thanks for the help guys! – Alex Jan 15 '15 at 19:29

0 Answers0