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.
An object that manages an ordered collection of data items and presents them using customizable layouts.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With