Skip to content

Instantly share code, notes, and snippets.

@MengTo
Created December 10, 2013 08:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MengTo/7887196 to your computer and use it in GitHub Desktop.
Save MengTo/7887196 to your computer and use it in GitHub Desktop.
Sample of a CollectionViewController with 3 sections
@property (nonatomic, strong) NSArray *sections;
- (void)viewDidLoad
{
[super viewDidLoad];
// Cell Sections in Array
self.sections = @[
@{@"identifier": @"firstCell"},
@{@"identifier": @"secondCell"},
@{@"identifier": @"thirdCell"},
];
}
#pragma mark -
#pragma mark UICollectionViewDataSource
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger)collectionView:(UICollectionView *)collectionView
numberOfItemsInSection:(NSInteger)section
{
return self.sections.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
id object = self.sections[indexPath.row];
UICollectionViewCell *cell = [collectionView
dequeueReusableCellWithReuseIdentifier:object[@"identifier"]
forIndexPath:indexPath];
return cell;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment