GestureRecognizer shouldReceiveTouch persisting in freed state causing the crash

I have a pretty simple UITableView that pushes a new view onto the stack. The new view has a gestureRecognizer pointer, which is initialized as follows

@synthesize swipeGestureLeft; - (void)viewDidLoad { swipeGestureLeft = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(toggleViewLeft)]; swipeGestureLeft.numberOfTouchesRequired = 1; swipeGestureLeft.delegate=self; swipeGestureLeft.direction = (UISwipeGestureRecognizerDirectionLeft); [self.view addGestureRecognizer:swipeGestureLeft]; } 

I also call the delegate method

 - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if (viewShown==1) { return NO; } return YES; } 

and in the dealloc method i have

 - (void)dealloc { NSLog(@"I AM IN DEALLOC"); swipeGestureLeft.delegate=nil; [self.view removeGestureRecognizer:swipeGestureLeft]; swipeGestureLeft=nil; } 

in my .h file i have

 @interface MyViewController : UIViewController <UIGestureRecognizerDelegate> 

now when I go back to go back to my table view, the view will be freed up (which I see due to NSLog crashes) now, when I try to scroll down my table view, the application crashes:

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

How to ensure that the delegate method is not called after the view is released.

+3
ios uitableview uigesturerecognizer dealloc
Sep 13 '13 at 1:01
source share
1 answer

SOLVED: I use the new iOS7 navigationController.interactivePopGestureRecognizer and set my delegate to "I".

After being released, I was not able to set his delegate to "nil". It was this object that saved (not sure if the word is correct) that the delegate was called, not the swipeLeftGesture object. Setting his delegate to zero at dealloc did the trick.

+7
Sep 13 '13 at 2:55 on
source share



All Articles