0

I am currently implementing infinite scrolling using collectionView by following this link. But I got stuck when I have to add collectionView sectionheader. The header doesn't shows up when I am implemeting the above link custom flow layout, but if I use default UICollectionViewLayout it's been displayed.

Implemented the method : -

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
rmaddy
  • 298,130
  • 40
  • 468
  • 517
Aditya Srivastava
  • 2,555
  • 2
  • 10
  • 22

2 Answers2

0
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize

This function is important for giving the size for collection view section header , and if you using the UICollectionViewLayout functions and pass the attribute layout then "referenceSizeForHeaderInSection" method is not need to implement

layoutAttributesForElements(in rect:)
Aman Gupta
  • 161
  • 1
  • 8
  • which method you are using "referenceSizeForHeaderInSection" or "layoutAttributesForElements". – Aman Gupta Dec 04 '17 at 10:41
  • Can you show me how to you registered the section. and i aman19ish@gmail.com – Aman Gupta Dec 04 '17 at 11:14
  • This answer actually helped me get unstuck from an issue I was having where I was already recalculating the header frame in my flowlayout subclass. Unfortunately I can't upvote it because I think it needs to be improved and expanded on for clarity in order to answer the original question. I'm not sure most people want to be touching something like `layoutAttributesForElements(in rect:)` – bitwit May 08 '18 at 21:09
  • Thank you for your suggestion bitwit – Aman Gupta May 09 '18 at 07:17
0

It works for me please try it hope helps to you

Set the UICollectionViewDelegateFlowLayout delegate

YourViewController : UIViewController <UICollectionViewDelegateFlowLayout>

if You want scrolling then you can use this method in didLoad method

self.yourcollectionview.scrollDirection = UICollectionViewScrollDirectionHorizontal

self.yourcollectionview.scrollDirection = UICollectionViewScrollDirectionVertical
Sanjukta
  • 1,021
  • 5
  • 16