Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed a crash when the gridView is released, because Apple calls -set…

…Delegate: in the dealloc method...

  • Loading branch information...
commit 0aa2cb688440404b5c0652229dc55b97306bc41a 1 parent 1897d80
@ldesroziers authored
Showing with 19 additions and 10 deletions.
  1. +19 −10 NRGridView/NRGridView/NRGridView.m
View
29 NRGridView/NRGridView/NRGridView.m
@@ -392,22 +392,31 @@ - (void)setDelegate:(id<NRGridViewDelegate>)aDelegate
{
if(delegate != aDelegate)
{
- [self willChangeValueForKey:@"delegate"];
- [self removeGestureRecognizer:_longPressGestureRecognizer];
- [_longPressGestureRecognizer release], _longPressGestureRecognizer=nil;
-
+ [self willChangeValueForKey:@"delegate"];
[super setDelegate:aDelegate];
delegate = aDelegate;
+ // Dixit Apple:
+ // "Don’t Use Accessor Methods in Initializer Methods and dealloc"
+ // ...
+ // Sure, but Y U DO CALL -setDelegate: with a nil argument when [super dealloc] is being called....????
+
+
if([aDelegate respondsToSelector:@selector(gridView:didLongPressCellAtIndexPath:)])
{
- _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(__handleLongPressGestureRecognizer:)];
- [_longPressGestureRecognizer setDelegate:self];
- [_longPressGestureRecognizer setNumberOfTapsRequired:0];
- [_longPressGestureRecognizer setNumberOfTouchesRequired:1];
-
- [self addGestureRecognizer:_longPressGestureRecognizer];
+ if(_longPressGestureRecognizer == nil)
+ {
+ _longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(__handleLongPressGestureRecognizer:)];
+ [_longPressGestureRecognizer setDelegate:self];
+ [_longPressGestureRecognizer setNumberOfTapsRequired:0];
+ [_longPressGestureRecognizer setNumberOfTouchesRequired:1];
+ [self addGestureRecognizer:_longPressGestureRecognizer];
+ }
+ [_longPressGestureRecognizer setEnabled:YES];
}
+ else
+ [_longPressGestureRecognizer setEnabled:NO];
+
[self didChangeValueForKey:@"delegate"];
}
Please sign in to comment.
Something went wrong with that request. Please try again.