From 6b410611c28314ca24b02b520788f56e65a98578 Mon Sep 17 00:00:00 2001 From: Gulam Moledina Date: Sun, 13 Nov 2011 15:08:57 -0500 Subject: [PATCH] Added synchronized block for thread safety --- GMGridView/API/GMGridView.m | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/GMGridView/API/GMGridView.m b/GMGridView/API/GMGridView.m index 42e03bc..e13b9e4 100644 --- a/GMGridView/API/GMGridView.m +++ b/GMGridView/API/GMGridView.m @@ -79,8 +79,8 @@ @interface GMGridView () @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,6 +1398,8 @@ - (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]; @@ -1402,8 +1407,7 @@ - (void)removeObjectAtIndex:(NSInteger)index self.firstPositionLoaded = self.lastPositionLoaded = GMGV_INVALID_POSITION; [self loadRequiredItems]; - - [self setNeedsLayout]; + [self relayoutItems]; } ];