Search code examples
iosobjective-cuitableviewuiviewuiswipegesturerecognizer

UIView swipe gesture conflicts with tableview in objective c


I have more than 20 viewcontrollers in my project and added swipe gesture in global viewcontroller class.

UISwipeGestureRecognizer *rightSwipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(navigateToPreviousScreen:)];
rightSwipeGesture.cancelsTouchesInView = YES;
rightSwipeGesture.direction = UISwipeGestureRecognizerDirectionRight;
[self.view addGestureRecognizer:rightSwipeGesture]; 

And override all sub class

- (void)navigateToPreviousScreen:(UISwipeGestureRecognizer *)sender { 

[self.navigationController popViewControllerAnimated:YES];}

Now i got a problem (not exactly a problem), The some of the viewcontrollers has tableviews and that swipe is not work sometimes(also got some touch sensitive issue). Is there a way to solve it. I set cancelsTouchesInView = No but seems problem occurs.

Thanks in Advance.


Solution

  • You should be able to fix this by implementing & returning YES in the following UIGestureRecognizerDelegate method in the parent class.

      - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
            return YES;
    }