---
title: "UICollectionVIew in iOS"  
description: "UICollectionVIew in iOS"  
author: "Samuel Fernandes"  
published: 2014-10-18  
updated: 2014-10-18  
canonical: https://www.mindstick.com/forum/2415/uicollectionview-in-ios  
category: "iphone"  
tags: ["iphone", "ios", "ios 7"]  
reading_time: 2 minutes  

---

# UICollectionVIew in iOS

I am Developing [Section](https://yourviews.mindstick.com/view/297/reservation-for-economically-weaker-section) based UICollection [view](https://yourviews.mindstick.com/view/84701/layoffs-in-google-india-2023-view) something like section based UITablview.but each section have different number of [data](https://www.mindstick.com/articles/13050/salesforce-aiming-to-dominate-predictive-analytics-with-data-science). but my issue is that it contain the similar data for every section.

Here is [Code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii) :-

```
- (void)viewDidLoad{    [super viewDidLoad];    //registering class for cell reusing    [self.collectionView registerClass:[CollectionViewCell class] forCellWithReuseIdentifier:@"CollectionCell"];    //registering class for view reusing    [self.collectionView registerClass:[SupplementaryView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"SupplementaryView"];   NSDictionary *animals = @{@"B" : @[@"Bear", @"Black Swan", @"Buffalo"],                @"C" : @[@"Camel", @"Cockatoo"],                @"D" : @[@"Dog", @"Donkey"],                @"E" : @[@"Emu"],                @"G" : @[@"Giraffe", @"Greater Rhea"],                @"H" : @[@"Hippopotamus", @"Horse"],                @"K" : @[@"Koala"],                @"L" : @[@"Lion", @"Llama"],                @"M" : @[@"Manatus", @"Meerkat"],                @"P" : @[@"Panda", @"Peacock", @"Pig", @"Platypus", @"Polar Bear"],                @"R" : @[@"Rhinoceros"],                @"S" : @[@"Seagull"],                @"T" : @[@"Tasmania Devil"],                @"W" : @[@"Whale", @"Whale Shark", @"Wombat"]};  NSArray*  animalSectionTitles = [[animals allKeys] sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)];}-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CollectionCell" forIndexPath:indexPath];    cell.label.text = @"Hello";    cell.backgroundColor = [UIColor darkGrayColor];    return cell;}-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{           return [animals count];}-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{    return [animalSectionTitles count];}-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath{    SupplementaryView *supplementaryView = [collectionView dequeueReusableSupplementaryViewOfKind:kind withReuseIdentifier:@"SupplementaryView" forIndexPath:indexPath];    if(kind == UICollectionElementKindSectionHeader){        supplementaryView.backgroundColor = [UIColor lightGrayColor];        supplementaryView.label.text = @"Header";    }    else{    }    return supplementaryView;}-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout referenceSizeForHeaderInSection:(NSInteger)section{    return CGSizeMake(500, 50);}
```

## Replies

### Reply by Takeshi Okada

Something like this could help you.\

```
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {int i=0;for (NSDictionary *item in animals) {    if (section==i) {        NSArray *lala=[animals objectForKey:item];        NSLog(@"%d",lala.count);        return lala.count;    }    i++;}}
```


---

Original Source: https://www.mindstick.com/forum/2415/uicollectionview-in-ios

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
