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.
ios uipangesturerecognizer
ancajic Feb 26 '15 at 15:17 2015-02-26 15:17
source share