Skip to content

Commit

Permalink
#130 also clears recycled cells when app enters backgound
Browse files Browse the repository at this point in the history
  • Loading branch information
Giulio Petek committed Apr 4, 2012
1 parent 7d451f7 commit 69b3221
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions KKGridView/KKGridView.m
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ - (void)_cleanupMetrics;
- (void)_commonReload;
- (void)_softReload;

// Notifications
- (void)_applicationDidReceiveMemoryWarning:(NSNotification *)notification;
- (void)_applicationDidEnterBackgound:(NSNotification *)notification;

// Torch-passers
- (void)_respondToBoundsChange;

Expand Down Expand Up @@ -205,7 +209,8 @@ - (void)_sharedInitialization
[self addObserver:self forKeyPath:@"contentOffset" options:NSKeyValueObservingOptionNew context:NULL];
[self addObserver:self forKeyPath:@"tracking" options:NSKeyValueObservingOptionNew context:NULL];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(applicationDidReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidReceiveMemoryWarning:) name:UIApplicationDidReceiveMemoryWarningNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidEnterBackgound:) name:UIApplicationDidEnterBackgroundNotification object:nil];
}

#pragma mark - Cleanup
Expand All @@ -214,6 +219,8 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidReceiveMemoryWarningNotification object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self name:UIApplicationDidEnterBackgroundNotification object:nil];

[self removeObserver:self forKeyPath:@"contentOffset"];
[self removeObserver:self forKeyPath:@"tracking"];
[self removeGestureRecognizer:_selectionRecognizer];
Expand Down Expand Up @@ -1560,7 +1567,12 @@ - (void) _removeUnusedCells
[_reusableCells removeAllObjects];
}

- (void) applicationDidReceiveMemoryWarning:(NSNotification *)notification
- (void) _applicationDidReceiveMemoryWarning:(NSNotification *)notification
{
[self _removeUnusedCells];
}

- (void) _applicationDidEnterBackgound:(NSNotification *)notification
{
[self _removeUnusedCells];
}
Expand Down

0 comments on commit 69b3221

Please sign in to comment.