Question

I have a UIview that contains a table view.

I want the user to be able to select items in the table view and I want to be able to identify taps in the parent view, outside the table view.

If I add a Tab Gesture Recognizer to the UIView, the user is unable to select items in the table view.

How can accomplish this task?

Was it helpful?

Solution

In this case, You've to add gesture to your view and you can cancel gesture call back method by doing if touch happen on tableview as below.

1) set TAG to your tableview . self.tableView.tag = TAG;

2) Now cancel gesture if touch on tableview as below

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
     id touchView= touch.view;
     if ([touchView isKindOfClass:[UITableView class]] || [touchView isKindOfClass:[UITableViewCell class]] )
    {

        if ( ((UIView*)touchView).tag == TAG) 
            return NO;
     }
     return YES;
}

OTHER TIPS

For those how uses @IBAction method. In Interface Builder Tap Gesture Recognizer in Attributes inspector just uncheck "Cancels touches in view".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top