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.
ios uitableview uigesturerecognizer dealloc
Eric Sep 13 '13 at 1:01 2013-09-13 01:01
source share