I want to show a UICollectionView which contains exactly 2 rows and 100 cells in each row.
// 1
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {
return 100;
}
// 2
- (NSInteger)numberOfSectionsInCollectionView: (UICollectionView *)collectionView {
return 2;
}
// 3
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath {
MyCell *cell = [cv dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.lbl.text = @"Data";
return cell;
}
I am getting this:
How can I specify a row number for UICollectionView? I want to create a 2x100 table.
For Swift : 3 Rows per Column (By using @SakhshiSingla Answer)
For 3 cells per row .. Add this code.
The more general approach to achieve n columns in collection view which is compatible in any orientation is
The Number of sections dictates how many cells will be in each row, assuming the cell size allows for it.
A section will always start a new row.
Try this: