Permalink
Browse files

try to restore previous contentOffset after a reloadData

This matches expected behavior; e.g. UITableView works the same.
We're still checking if the offset is acceptable with min/max values.
  • Loading branch information...
1 parent c8c6b8e commit b6ec99f0a6bfaffd5e06c898f98e0e4366fe61a7 @steipete steipete committed with Dec 14, 2011
Showing with 7 additions and 1 deletion.
  1. +7 −1 GMGridView/API/GMGridView.m
@@ -1277,6 +1277,8 @@ - (void)receivedMemoryWarningNotification:(NSNotification *)notification
- (void)reloadData
{
+ CGPoint previousContentOffset = _scrollView.contentOffset;
+
[[self itemSubviews] enumerateObjectsUsingBlock:^(id obj, NSUInteger index, BOOL *stop){
[(UIView *)obj removeFromSuperview];
}];
@@ -1291,7 +1293,11 @@ - (void)reloadData
_numberTotalItems = numberItems;
[self recomputeSize];
- _scrollView.contentOffset = _minPossibleContentOffset;
+
+ CGPoint newContentOffset = CGPointMake(MIN(_maxPossibleContentOffset.x, previousContentOffset.x), MIN(_maxPossibleContentOffset.y, previousContentOffset.y));
+ newContentOffset = CGPointMake(MAX(newContentOffset.x, _minPossibleContentOffset.x), MAX(newContentOffset.y, _minPossibleContentOffset.y));
+
+ _scrollView.contentOffset = newContentOffset;
[self loadRequiredItems];

0 comments on commit b6ec99f

Please sign in to comment.