Skip to content
Browse files

Added synchronized block for thread safety

  • Loading branch information...
1 parent d3c7459 commit 6b410611c28314ca24b02b520788f56e65a98578 @gmoledina committed Nov 13, 2011
Showing with 18 additions and 14 deletions.
  1. +18 −14 GMGridView/API/GMGridView.m
View
32 GMGridView/API/GMGridView.m
@@ -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
@@ -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;
@@ -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];
}
];

0 comments on commit 6b41061

Please sign in to comment.
Something went wrong with that request. Please try again.