Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView number of cells in the section

How to count the number of cells in the section? I need to know the number of cells in the section during the cell selection.

like image 477
Alexey Avatar asked Dec 05 '13 07:12

Alexey


People also ask

What is a UICollectionView?

An object that manages an ordered collection of data items and presents them using customizable layouts.

How do you create a collection view with multiple sections?

You need to implement a custom UICollectionViewLayout. With a horizontal flow layout it's going to fill from top to bottom first, then move to the right. Since you have two rows, as specified in sizeForItemAt, section 0 will fill from top to bottom, then right to left, and so will section 1.

How does swift implement UICollectionView?

Select the Main storyboard from the file browser. Add a CollectionView by pressing command shift L to open the storyboard widget window. Drag the collectionView onto the main view controller. Add constraints to the UICollectionView widget to ensure that the widget fills the screen on all devices.


1 Answers

Use this method for the the collection view to find number of items in a section

- (NSInteger)numberOfItemsInSection:(NSInteger)section;

You can call it using your UICollectionView object as.

NSInteger numberOfItems = [myCollectionView numberOfItemsInSection:2];

Where 2 is the section for which you want to find the number of items.

like image 84
hemkaran_raghav Avatar answered Oct 19 '22 20:10

hemkaran_raghav