Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple UICollectionView in the same ViewController

I am using custom UICollectionView layout for having different size of cells and I am not able to have a section in this.

Is it good idea to use multiple UICollectionViews in the same UIViewController? Any suggestion please?

like image 238
user2181649 Avatar asked Feb 15 '23 04:02

user2181649


1 Answers

it's simple

for every UICollectionView Delegates

- (NSUInteger)maximumNumberOfColumnsForCollectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout

- (CGFloat)collectionView:(UICollectionView*)collectionView layout:(UICollectionViewLayout*)collectionViewLayout
heightForItemAtIndexPath:(NSIndexPath*)indexPath

- (UICollectionViewCell*)collectionView:(UICollectionView*)collectionView
 cellForItemAtIndexPath:(NSIndexPath*)indexPath
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section`
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView*)collectionView`

write condition inside:

    if (collectionView == myCollectionView1)
    {
    // do this 
    }
    else if (collectionView == myCollectionView2)
    {
    // do this 
    }

lets say for example in

- (NSInteger)collectionView:(UICollectionView*)collectionView numberOfItemsInSection:(NSInteger)section 
{
    if (collectionView == myCollectionView1)
    {
     return 12;
    }
    else if (collectionView == myCollectionView2)
    {
     return 7; 
    }
    return 0;
}
like image 146
Zeeshan Avatar answered Feb 17 '23 03:02

Zeeshan