Search code examples
objective-cuitableviewuipangesturerecognizerxcode9.1

Handle Pan Gesture on UITableView cell


I added MARKRangeSlider to UITableViewCell and its working as expected. While dragging handle, the table view controller is also popping up to previous view controller. How could I avoid or prevent the action of popping up?

I tried following code by adding delegate but failed to achieve the result.

 - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
         // CGPoint velocity = [panGestureRecognizer  velocityInView:panGestureRecognizer.view];
         // return fabs(velocity.y) > fabs(velocity.x);
        CGPoint translation = [(UIPanGestureRecognizer *)gestureRecognizer translationInView:gestureRecognizer.view.superview];
        // if you want an NSString
        NSLog(@"gestureRecognizer-superview %@", NSStringFromClass([gestureRecognizer.view.superview class]) );
        return fabs(translation.x) > fabs(translation.y);
    }


- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
    if (otherGestureRecognizer == leftPanRecognizer) {
        return YES;
    }
    if (otherGestureRecognizer == rightPanRecognizer) {
        return YES;
    }
    return NO;
}

Its intermittent issue. Please let me know how to deal it?

Thanks in advance


Solution

  • I found the solution,

    In UITableViewController or UIViewController which has UITableView has to disable interactivePopGestureRecognizer in viewDidAppear and in same Controller developer has to enable interactivePopGestureRecognizer in viewWillDisAppear . Hope it helps.