Using Two CollectionViews

Something I’ve noticed myself doing is that I’ve been needing to set up more than one Collection View in a View Controller. This isn’t something that happens a lot, but when it does, it’s good to have an example or two in your notes from which to work.

The only real new functionality is to add some If-Then Statements to some of our CollectionView Data Source Methods in order to check on which Collection View is requesting data.

- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section {

    if ( view == collectionView1 ) {

// Return the Number of Cells in collectionView1

   }

    if ( view ==collectionView2) {

// Return the Number of Cells in collectionView2;

   }

}

- (UICollectionViewCell *)collectionView:(UICollectionView *)view cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    if ( view == collectionView1 ) {

// Return the Cells in collectionView1

   }

    if ( view ==collectionView2) {

// Return the Cells in collectionView2;

   }

}

All in all, it’s pretty simple.