0

As title says. I had one controller where I was setting interactivePopGestureRecognizer.delegate to handle logic when to allow back swipe gesture and when not. It worked. But now I noticed that once I setup the delegate, the back swipe stops working. It really causes that one line of code. But why?

Yes, the controller where I used to handle the backswipe logic had everything needed (UIGestureRecognizerDelegate protocol, gestureRecognizerShouldBegin delegate method with return YES), but as I say, I discovered in another controller that by just calling the one line of the following code, back swipe doesn't work anymore. (Yes this another controller conforms to UIGestureRecognizerDelegate protocol)

self.navigationController.interactivePopGestureRecognizer.delegate = self;

It doesn't help if I add also:

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

or

self.navigationController.interactivePopGestureRecognizer.enabled = YES;

I wonder what is causing this? If I don't call that one line of code, back swipe works! And it even worked in the another controller where I handled the logic as I said.

Edit: I was setting the delegate from viewDidLoad. I tried also from viewDidAppear, but nothing.

luky
  • 2,263
  • 3
  • 22
  • 40

2 Answers2

1

The issue is because you are setting multiple ViewController as the delegate. Once you set any ViewController as the UIGestureRecognizerDelegate delegate, that ViewController is responsible for handling the gesture and previously set any delegate will be invalid

To fix the issue you can set the delegate again when view appears in viewWillAppear

self.navigationController.interactivePopGestureRecognizer.delegate = self;
Mohammed Shakeer
  • 1,446
  • 16
  • 23
  • Hi Mohammed. Thank you for reply. In my case, the method is called only once, and only on the second controller. – luky Aug 23 '16 at 06:40
  • Well, in two, but i am opening only the second. If you get me, so in fact only in one. And remember, if i dont set the delegate in the controller, backswipe works. But once i set it, it doesnt work.. – luky Aug 23 '16 at 06:47
  • 1
    I think then some other code is causing the issue. I tried a sample project with the code you added and I too had that issue. I suggest you create a sample app with only navigation related code, nothing else. – Mohammed Shakeer Aug 23 '16 at 06:55
  • I found the solution, I will post it below. Thank you for trying and help. – luky Aug 23 '16 at 07:02
1

For some reason, if I add the following code to controller, back swipe again works. Maybe it is because i have scrollview in the controller view, but it was working before even without the following code and then it stopped. Strange. (May be i didnt have tableview on the controller where it worked, i dont remember, but i was trying it even with hidden table when it stopped working)

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

As said here.

Community
  • 1
  • 1
luky
  • 2,263
  • 3
  • 22
  • 40