Permalink
Browse files

Fixed ARC leaks, some weak properties was not set to __unsafe_unretai…

…ned and one animation wasn't properly converted
  • Loading branch information...
1 parent 4072978 commit be0114c3e50ca326beb95b65782928e56667d4cf @augard augard committed Jan 3, 2012
Showing with 34 additions and 47 deletions.
  1. +5 −5 Classes/AQGridView.h
  2. +27 −40 Classes/AQGridView.m
  3. +1 −1 Classes/AQGridViewData.h
  4. +1 −1 Classes/AQGridViewUpdateInfo.h
View
@@ -112,7 +112,7 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
NSIndexSet * _animatingIndices;
NSMutableIndexSet * _highlightedIndices;
- UIView * _touchedContentView; // weak reference
+ UIView * __unsafe_unretained _touchedContentView; // weak reference
UIView * _backgroundView;
UIColor * _separatorColor;
@@ -151,10 +151,10 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
unsigned delegateWillDisplayCell:1;
unsigned delegateWillSelectItem:1;
- unsigned delegateWillSelectItemMultiTouch:1;
+ unsigned delegateWillSelectItemMultiTouch:1;
unsigned delegateWillDeselectItem:1;
unsigned delegateDidSelectItem:1;
- unsigned delegateDidSelectItemMultiTouch:1;
+ unsigned delegateDidSelectItemMultiTouch:1;
unsigned delegateDidDeselectItem:1;
unsigned delegateGestureRecognizerActivated:1;
unsigned delegateAdjustGridCellFrame:1;
@@ -168,8 +168,8 @@ extern NSString * const AQGridViewSelectionDidChangeNotification;
} _flags;
}
-@property (nonatomic, assign) IBOutlet id<AQGridViewDataSource> dataSource;
-@property (nonatomic, assign) IBOutlet id<AQGridViewDelegate> delegate;
+@property (nonatomic, unsafe_unretained) IBOutlet id<AQGridViewDataSource> dataSource;
+@property (nonatomic, unsafe_unretained) IBOutlet id<AQGridViewDelegate> delegate;
@property (nonatomic, assign) AQGridViewLayoutDirection layoutDirection;
View
@@ -88,7 +88,6 @@ - (void) deleteVisibleCell: (AQGridViewCell *) cell atIndex: (NSUInteger) visibl
@interface AQGridView ()
@property (nonatomic, copy) NSIndexSet * animatingIndices;
-- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context;
@end
@@ -908,8 +907,8 @@ - (void) setupUpdateAnimations
- (void) endUpdateAnimations
{
NSAssert([_updateInfoStack lastObject] != nil, @"_updateInfoStack should not be empty at this point" );
-
- AQGridViewUpdateInfo * info = [_updateInfoStack lastObject];
+
+ __block AQGridViewUpdateInfo * info = [_updateInfoStack lastObject];
if ( info.numberOfUpdates == 0 )
{
@@ -931,46 +930,34 @@ - (void) endUpdateAnimations
[NSException raise: NSInternalInconsistencyException format: @"Invalid number of items in AQGridView: Started with %u, added %u, deleted %u. Expected %u items after changes, but got %u", (unsigned)_gridData.numberOfItems, (unsigned)numAdded, (unsigned)numDeleted, (unsigned)expectedItemCount, (unsigned)actualItemCount];
}
- // there's a race condition with the info's removal from the stack if there are no animations taking place,
- // where -cellUpdateAnimationStopped:finished:context: is called immediately, before we've finished with the
- // object. Therefore we retain it while we want to use it, just in case
-
[info cleanupUpdateItems];
_animationCount++;
//NSAssert(_animationCount == 1, @"Stacked animations occurring!!");
-
- [UIView beginAnimations: @"CellUpdates" context: (void*)objc_unretainedPointer(info)];
- [UIView setAnimationDelegate: self];
- [UIView setAnimationDidStopSelector: @selector(cellUpdateAnimationStopped:finished:context:)];
- [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
- [UIView setAnimationDuration: 0.3];
-
- self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];
-
-
- _gridData = [info newGridViewData];
- if ( _selectedIndex != NSNotFound )
- _selectedIndex = [info newIndexForOldIndex: _selectedIndex];
-
- _reloadingSuspendedCount--;
- [UIView commitAnimations];
-}
-
-- (void) cellUpdateAnimationStopped: (NSString *) animationID finished: (BOOL) finished context: (void *) context
-{
- AQGridViewUpdateInfo * info = (__bridge AQGridViewUpdateInfo *)context;
-
- // if nothing was animated, we don't have to do anything at all
-// if ( self.animatingCells.count != 0 )
- [self fixCellsFromAnimation];
-
- // NB: info becomes invalid at this point
- [_updateInfoStack removeObject: info];
- _animationCount--;
-
- //_reloadingSuspendedCount--;
- if ( _flags.delegateDidEndUpdateAnimation == 1 )
- [self.delegate gridViewDidEndUpdateAnimation: self];
+
+ [UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionCurveEaseInOut
+ animations:^(void) {
+ self.animatingCells = [info animateCellUpdatesUsingVisibleContentRect: [self gridViewVisibleBounds]];
+
+
+ _gridData = [info newGridViewData];
+ if ( _selectedIndex != NSNotFound )
+ _selectedIndex = [info newIndexForOldIndex: _selectedIndex];
+
+ _reloadingSuspendedCount--;
+ }
+ completion:^(BOOL finished) {
+ // if nothing was animated, we don't have to do anything at all
+ // if ( self.animatingCells.count != 0 )
+ [self fixCellsFromAnimation];
+
+ // NB: info becomes invalid at this point
+ [_updateInfoStack removeObject: info];
+ _animationCount--;
+
+ //_reloadingSuspendedCount--;
+ if ( _flags.delegateDidEndUpdateAnimation == 1 )
+ [self.delegate gridViewDidEndUpdateAnimation: self];
+ }];
}
- (void) beginUpdates
View
@@ -40,7 +40,7 @@
@interface AQGridViewData : NSObject <NSCopying, NSMutableCopying>
{
- AQGridView * _gridView; // weak reference
+ AQGridView * __unsafe_unretained _gridView; // weak reference
CGSize _boundsSize;
AQGridViewLayoutDirection _layoutDirection;
CGSize _desiredCellSize; // NB: 'cell' here means a grid cell -- i.e. constant size, tessellating
@@ -72,7 +72,7 @@
NSMutableIndexSet * _onlyMovedIndices;
// needs to ask the grid view for cells
- AQGridView * _gridView; // weak reference
+ AQGridView * __unsafe_unretained _gridView; // weak reference
NSMutableSet * _animatingCells;
}

0 comments on commit be0114c

Please sign in to comment.