0

I am creating my own flowlayout but I am having problems getting the correct collectionViewContentSize, my data is an array of arrays, 5 arrays an each array have multiple items.

Is this correct numberOfItemsInSection:0 ? or do i need check all the arrays to find the array that have more items and then calculate xSize with the items on that section ?

-(CGSize)collectionViewContentSize {

NSInteger xSize = [self.collectionView numberOfItemsInSection:0] * (itemWidth + space); // "space" is for spacing between cells.
NSInteger ySize = [self.collectionView numberOfSections] * (itemHeight + space);

NSLog(@"size %f, %f", xSize, ySize);
return CGSizeMake(xSize, ySize);

}

Thanks.

HernandoZ
  • 742
  • 2
  • 12
  • 24

2 Answers2

2

Anyone wanting to learn how to do this I found this great tutorial From Bryan Hensen

HernandoZ
  • 742
  • 2
  • 12
  • 24
0

You have both axis being set. Typically, you only need to set one axis (the scrolling axis) because the screen edge (or the edge of your collectionView) in the non-scrolling direction will be set for you. OTher than that, yeah, you'll have to go through each array to get a total height.

Nick Terry
  • 171
  • 12
  • Thanks, do i have to the same for - (UICollectionViewLayoutAttributes *)layoutAttributesForItemAtIndexPath:(NSIndexPath *)path and -(NSArray*)layoutAttributesForElementsInRect:(CGRect)rect . iterate through each section ... – HernandoZ Aug 21 '13 at 06:52
  • Those are typically used to modify specific pieces (a single cell or all cells within a rect) rather than the entire collectionView. The Apple docs cover how pretty well. See "Understanding the Core Layout Process" https://developer.apple.com/library/ios/documentation/WindowsViews/Conceptual/CollectionViewPGforIOS/CreatingCustomLayouts/CreatingCustomLayouts.html#//apple_ref/doc/uid/TP40012334-CH5-SW1 – Nick Terry Aug 22 '13 at 17:30