Home Programmatically scroll to a supplementary view within UICollectionView
Reply: 0

Programmatically scroll to a supplementary view within UICollectionView

user8370
1#
user8370 Published in September 19, 2018, 6:42 pm

I am using UICollectionView to display photos in sections. Each section has a supplementary view as a header and is supplied via the method: viewForSupplementaryElementOfKind.

I have a scrubber on the side that allows the user to jump from section to section. For now I am scrolling to the first item in the section using scrollToItemAtIndexPath:atScrollPosition:animated:, but what I really want is to scroll the collectionView so that that section's header is at the top of the screen, not the first cell. I do not see an obvious method to do this with. Do any of you have a work around?

I suppose I could scroll to the first item of the section, and then offset that by the supplementary height plus the offset between the items and header if it comes down to that (there is a method for scrolling to point coordinates of the contentView). However if there is a simpler way, I'd like to know.

Thanks.

share|improve this question
  • what's the problem about it? it should work nice since every supplementary view has its index path – Bogdan Weidmann Apr 28 '13 at 14:00
  • Yes, they do indeed have indexPaths. I did a print out for both delegate methods that prep the cell and supplementary cell. The indexPaths are not mutually exclusive, rather they look like two distict sets with nonuniue indexPaths. This will probably not paste well here, but: !!! Cell index path 0 0 !!! Supp index path 0 0 !!! Cell index path 0 1 !!! Cell index path 0 2 !!! Cell index path 0 3 !!! Cell index path 0 4 !!! Cell index path 0 5 !!! Cell index path 0 6 !!! Cell index path 0 7 !!! Cell index path 0 8 !!! Cell index path 0 9 !!! Cell index path 0 10 !!! Cell index path 0 11 – VaporwareWolf Apr 29 '13 at 16:54
  • I should state that I am printing out indexPath.section indexPath.item. Is there another property that I'm overlooking that would set these apart? You can see that [0 0] is in the cell view and supplementary view from what I have printed. – VaporwareWolf Apr 29 '13 at 16:57

4 Answers 4

active oldest votes
up vote 37 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.345626 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO