You put this code inside ViewController.m, so that it just active when you tap on self.view.Your scrollView overlay your self.view so that action not active.
Subclass your scrollView and select type in your IB, inside YourScrollView.m, add this code:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *aTouch = [touches anyObject];
if (aTouch.tapCount == 1)
{
CGPoint p = [aTouch locationInView:self];
for (UIView *aView in self.subviews) {
if (([aView isKindOfClass:[UITableView class]])&&(!CGRectContainsPoint(aView.frame, p)))
{
[aView setHidden:YES];
}
}
}
}