0

I would like to have two or more CollectionView in one single view (UIViewController "delegate/sourcedata").

enter image description here

I have already done one and it works fine, but I would like to have another one in the same page that works different from the first one. I don't need sections, I need two different CollectionView in one page if it's possible. How could I do that?

Dilip Manek
  • 9,095
  • 5
  • 44
  • 56
Tortuga
  • 97
  • 3
  • 10
  • 2
    I think your answer is here: [Follow this link](http://stackoverflow.com/questions/12850396/multiple-uicollectionview-in-one-controller) – Ponting Jun 18 '13 at 16:28

2 Answers2

2

There is nothing to prevent you from doing this. You just need to create it separately and provide the necessary code to handle each as you want to within the delegate. Each delegate method has the collectionView passed to it on each call, so it isn't a huge problem to write different code depending on which of the two collection views is active.

For example,

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

The first argument is the specific collection view making the call, so you can distinguish what value to return for it.

If you're going to have a lot of code handling these two cvs you might consider whether it makes sense to subclass them but that's a different question.

You're going to create two of them like so:

UICollectionView *cv1 = [[UICollectionView alloc] initWithFrame:CGRectMake(10.0f, 100.0f, 525.0f, 500.0f) collectionViewLayout:flowLayout];

UICollectionView *cv2 [[UICollectionView alloc] init ...

Then, you'll add each as a subview. Handle the delegate methods based on whether cv1 or cv2 is passed in. Shouldn't be a big problem, although a bit of a pain.

RegularExpression
  • 3,531
  • 2
  • 25
  • 36
0

You can directly drag and drop the UICollectionView form xib. If its going below the screen then you have to add multiple UICollectionViews in that scrollview.

GSD
  • 436
  • 3
  • 13