Skip to content

Instantly share code, notes, and snippets.

@vikdenic
Created February 13, 2016 23:01
Show Gist options
  • Select an option

  • Save vikdenic/c97c1acdedd5acdd3aa8 to your computer and use it in GitHub Desktop.

Select an option

Save vikdenic/c97c1acdedd5acdd3aa8 to your computer and use it in GitHub Desktop.
Objective-C Category to return all cells from a UICollectionView instance
#import "UICollectionView+CellRetrieval.h"
@implementation UICollectionView (CellRetrieval)
-(NSArray *) allCells {
NSMutableArray *cells = [[NSMutableArray alloc] init];
for (NSInteger j = 0; j < [self numberOfSections]; ++j)
{
for (NSInteger i = 0; i < [self numberOfItemsInSection:j]; ++i)
{
[cells addObject:[self cellForItemAtIndexPath:[NSIndexPath indexPathForRow:i inSection:j]]];
}
}
return [cells copy];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment