문제

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?

도움이 되었습니까?

해결책

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;
}

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top