[ViewController gestureRecognizer: shouldRecognizeSimultaneousWithGestureRecognizer:]: message sent to the freed instance

I have a simple script.

I myViewController on the navigation stack.

myViewController basically shows the collection view across the screen. I added an additional UIPanGestureRecognizer to this collection view and set myViewController as my delegate. I keep a strong reference to this rotation recognition recognizer inside myViewController .

When I click "Back", myViewController appears from the navigation stack and is freed. The myViewController dealloc is called properly. Up to this point, everything is working as expected.

Then I try to open the same myViewController as the first time, and the message crashes:

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

I have this method implemented in myViewController , and it always returns YES . But this should not even matter, because no one should even call this method, because none of them should have a strong reference to it. Obviously, someone is still holding a weak reference, as the dealloc method was called by the only instance that ever existed.

Even the init myViewController method is myViewController .

I tried putting the following code in both dealloc and viewWillDisappear :

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

But that didn’t change anything. Each time the same thing - myViewController gets initialized and displays normally for the first time. The second time I try to initialize and click, an exception is thrown. Obviously, this is due to gesture recognition, which I added, but I don’t see how.

+2
ios uipangesturerecognizer
Feb 26 '15 at 15:17
source share
1 answer

The answer to this question ended up being that my problem was very similar: gestureRecognizer shouldReceiveTouch, persisting in a disconnected view causing crashes

I incorrectly set self.navigationController.interactivePopGestureRecognizer.delegate for myself.

So, although the error reported by NSzombie was in a different class. This gesture recognition was not really the culprit, it was my interactivePopGestureRecognizer.

+3
Mar 04 '15 at 20:56
source share



All Articles