diff --git a/BroBoard/BroBoard/PSBroView.m b/BroBoard/BroBoard/PSBroView.m index 71ae288..11922f6 100644 --- a/BroBoard/BroBoard/PSBroView.m +++ b/BroBoard/BroBoard/PSBroView.m @@ -86,7 +86,11 @@ - (void)fillViewWithObject:(id)object { self.imageView.image = [UIImage imageWithData:data]; }]; - self.captionLabel.text = [object objectForKey:@"title"]; + NSString *title = [object objectForKey:@"title"]; + if ([title isKindOfClass:[NSString class]]) + { + self.captionLabel.text = title; + } } + (CGFloat)heightForViewWithObject:(id)object inColumnWidth:(CGFloat)columnWidth { @@ -105,7 +109,10 @@ + (CGFloat)heightForViewWithObject:(id)object inColumnWidth:(CGFloat)columnWidth NSString *caption = [object objectForKey:@"title"]; CGSize labelSize = CGSizeZero; UIFont *labelFont = [UIFont boldSystemFontOfSize:14.0]; - labelSize = [caption sizeWithFont:labelFont constrainedToSize:CGSizeMake(width, INT_MAX) lineBreakMode:UILineBreakModeWordWrap]; + if ([caption isKindOfClass:[NSString class]]) + { + labelSize = [caption sizeWithFont:labelFont constrainedToSize:CGSizeMake(width, INT_MAX) lineBreakMode:UILineBreakModeWordWrap]; + } height += labelSize.height; height += MARGIN; diff --git a/BroBoard/BroBoard/PSViewController.m b/BroBoard/BroBoard/PSViewController.m index be0f65e..ec8c2da 100644 --- a/BroBoard/BroBoard/PSViewController.m +++ b/BroBoard/BroBoard/PSViewController.m @@ -137,7 +137,7 @@ - (NSInteger)numberOfViewsInCollectionView:(PSCollectionView *)collectionView { - (PSCollectionViewCell *)collectionView:(PSCollectionView *)collectionView viewAtIndex:(NSInteger)index { NSDictionary *item = [self.items objectAtIndex:index]; - PSBroView *v = (PSBroView *)[self.collectionView dequeueReusableView]; + PSBroView *v = (PSBroView *)[self.collectionView dequeueReusableView:[PSBroView class]]; if (!v) { v = [[PSBroView alloc] initWithFrame:CGRectZero]; } diff --git a/PSCollectionView.h b/PSCollectionView.h index 0bbe669..5553cff 100644 --- a/PSCollectionView.h +++ b/PSCollectionView.h @@ -55,7 +55,7 @@ Dequeues a reusable view that was previously initialized This is similar to UITableView dequeueReusableCellWithIdentifier */ -- (UIView *)dequeueReusableView; +- (PSCollectionViewCell *)dequeueReusableView:(Class) inClass; @end diff --git a/PSCollectionView.m b/PSCollectionView.m index 768c76c..13e6838 100644 --- a/PSCollectionView.m +++ b/PSCollectionView.m @@ -115,7 +115,7 @@ @interface PSCollectionView () @property (nonatomic, assign, readwrite) NSInteger numCols; @property (nonatomic, assign) UIInterfaceOrientation orientation; -@property (nonatomic, retain) NSMutableSet *reuseableViews; +@property (nonatomic, retain) NSMutableArray *reuseableViews; @property (nonatomic, retain) NSMutableDictionary *visibleViews; @property (nonatomic, retain) NSMutableArray *viewKeysToRemove; @property (nonatomic, retain) NSMutableDictionary *indexToRectMap; @@ -178,7 +178,7 @@ - (id)initWithFrame:(CGRect)frame { self.numColsLandscape = 0; self.orientation = [UIApplication sharedApplication].statusBarOrientation; - self.reuseableViews = [NSMutableSet set]; + self.reuseableViews = [NSMutableArray array]; self.visibleViews = [NSMutableDictionary dictionary]; self.viewKeysToRemove = [NSMutableArray array]; self.indexToRectMap = [NSMutableDictionary dictionary]; @@ -417,16 +417,23 @@ - (void)removeAndAddCellsIfNecessary { #pragma mark - Reusing Views -- (PSCollectionViewCell *)dequeueReusableView { - PSCollectionViewCell *view = [self.reuseableViews anyObject]; - if (view) { - // Found a reusable view, remove it from the set - [view retain]; - [self.reuseableViews removeObject:view]; - [view autorelease]; +- (PSCollectionViewCell *)dequeueReusableView:(Class) inClass { + NSUInteger i = 0; + NSUInteger count = [self.reuseableViews count]; + PSCollectionViewCell *view = nil; + for (i = 0; i < count; i++) + { + view = [self.reuseableViews objectAtIndex:i]; + if ([view isKindOfClass:inClass]) { + // Found a reusable view, remove it from the set + [view retain]; + [self.reuseableViews removeObject:view]; + [view autorelease]; + return view; + } } - return view; + return nil; } - (void)enqueueReusableView:(PSCollectionViewCell *)view {