问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/28746123/viewcontroller-gesturerecognizershouldrecognizesimultaneouslywithgesturerecogn