[ViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance
Asked Answered
L

1

2

I have a simple scenario.

I push myViewController onto navigation stack.

myViewController is basically showing a collection view over entire screen. I added an additional UIPanGestureRecognizer on this collection view and set myViewController as its delegate. I am retaining a strong reference to that pan gesture recognizer inside myViewController.

When I tap Back, myViewController gets popped from the navigation stack and deallocated. The myViewController's dealloc method gets called as it should. Up to this point everything works as expected.

Then I try to open the same myViewController like the first time and the crash occurs with the message:

[MyViewController gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:]: message sent to deallocated instance

I have this method implemented in myViewController and it always returns YES. But this shouldn't even matter because no one should even be calling this method because none should have a strong reference to it. Obviously someone is still holding a weak reference since the dealloc method was called on the only instance that ever existed.

Not even the init method of the MyViewController gets called.

I tried to put the following code both in dealloc and in viewWillDisappear:

[self.myPanGestureRecognizer removeTarget:self action:@selector(panGestureAction:)];
    [self.collectionView removeGestureRecognizer:self.myPanGestureRecognizer];
    self.myPanGestureRecognizer.delegate = nil;
    self.myPanGestureRecognizer = nil;

But, it didn't change anything. Every time the same thing - myViewController gets initialized and displayed normally the first time. The second time I try to initialize and push, the exception occurs. Obviously, it is related to the pan gesture recognizer that I added, but I don't see how.

Loculus answered 26/2, 2015 at 15:17 Comment(1)
I have a similar problem, but I think it's related to another gesture recognizer. If I comment out the line used to add my custom gesture recognizer, I still get the error. Is there some other recognizer that is trying to pass a message to your deallocated view?Vineyard
V
3

The answer to this question ended up fixing my issue that was very similar: gestureRecognizer shouldReceiveTouch persisting in deallocated view causing crash

I was incorrectly setting self.navigationController.interactivePopGestureRecognizer.delegate to self.

So even though the error reported from the NSZombie was in another class. It's gesture recognizer was not actually the culprit, it was my interactivePopGestureRecognizer.

Vineyard answered 4/3, 2015 at 20:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.