I have a view configured with two UICollectionViews. Each of these representations has an array supporting it with different sizes. collection1 is supported by array1, and collection2 is supported by array2. The problem is that the return number for collection1 from numberOfItemsInSection applies to both views of the collection.
For example, if array1 is 4 and array2 is 5, both collections will display 4 elements. If array1 is size 5 and array2 is size 4 when I look at collection2 the way it calls cellForItemAtIndexPath with itemIndex from 5 for collection2, and I get an NSRangeException.
How can I make each CollectionView my own size?
- (NSInteger)collectionView:(UICollectionView *)view numberOfItemsInSection:(NSInteger)section; { if(view == self.colleciton1){ return self.array1.count; } else if (view == self.collection2){ return self.array2.count; } return 0; } - (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath; { if(cv == self.collection1){ CharacterCell *cell = [cv dequeueReusableCellWithReuseIdentifier:FIRST_CELL_IDENTIFIER forIndexPath:indexPath]; cell.label.text = self.array1[indexPath.item]; return cell; } else if (cv == self.collection2){ EpisodeCell *cell = [cv dequeueReusableCellWithReuseIdentifier:SECOND_CELL_IDENTIFIER forIndexPath:indexPath]; cell.label.text = self.array2[indexPath.item]; return cell; } return nil; }
I have included the git repository with a project illustrating the problem.
git @ github.com: civatrix / MultipleCollectionViews.git
ios uicollectionview
Civatrix Oct 12 '12 at 0:00 2012-10-12 00:00
source share