Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added synchronized block for thread safety
  • Loading branch information
gmoledina committed Nov 13, 2011
1 parent d3c7459 commit 6b41061
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions GMGridView/API/GMGridView.m
Expand Up @@ -79,8 +79,8 @@ @interface GMGridView () <UIGestureRecognizerDelegate, UIScrollViewDelegate>

@property (nonatomic, readonly) BOOL itemsSubviewsCacheIsValid;
@property (nonatomic, strong) NSArray *itemSubviewsCache;
@property (nonatomic) NSInteger firstPositionLoaded;
@property (nonatomic) NSInteger lastPositionLoaded;
@property (atomic) NSInteger firstPositionLoaded;
@property (atomic) NSInteger lastPositionLoaded;


// Gestures
Expand Down Expand Up @@ -1019,20 +1019,23 @@ - (NSArray *)itemSubviews
}
else
{
NSMutableArray *itemSubViews = [[NSMutableArray alloc] initWithCapacity:_numberTotalItems];

for (UIView * v in [_scrollView subviews])
@synchronized(_scrollView)
{
if ([v isKindOfClass:[GMGridViewCell class]])
NSMutableArray *itemSubViews = [[NSMutableArray alloc] initWithCapacity:_numberTotalItems];

for (UIView * v in [_scrollView subviews])
{
[itemSubViews addObject:v];
if ([v isKindOfClass:[GMGridViewCell class]])
{
[itemSubViews addObject:v];
}
}

subviews = itemSubViews;

self.itemSubviewsCache = [subviews copy];
_itemsSubviewsCacheIsValid = YES;
}

subviews = itemSubViews;

self.itemSubviewsCache = [subviews copy];
_itemsSubviewsCacheIsValid = YES;
}

return subviews;
Expand Down Expand Up @@ -1395,15 +1398,16 @@ - (void)removeObjectAtIndex:(NSInteger)index
cell.alpha = 0;

[_scrollView scrollRectToVisible:CGRectMake(origin.x, origin.y, _itemSize.width, _itemSize.height) animated:NO];

[self recomputeSize];
}
completion:^(BOOL finished){
[self queueReusableCell:cell];
[cell removeFromSuperview];

self.firstPositionLoaded = self.lastPositionLoaded = GMGV_INVALID_POSITION;
[self loadRequiredItems];

[self setNeedsLayout];
[self relayoutItems];
}
];

Expand Down

0 comments on commit 6b41061

Please sign in to comment.