Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView scroll to specific section

Using Objective C and Xcode I have created a UICollectionView with 10 sections and all works fine. Is there anyway to set the section to which is viewed when first shown? By default it shows sections 0-9, but I want it to start at section 5.

like image 630
Bogiemon Avatar asked Apr 16 '13 22:04

Bogiemon


1 Answers

You can call scrollToItemAtIndexPath:atScrollPosition:animated: in your viewDidAppear: method.

You can hold a reference to the cell you want to scroll to, then use indexPathForCell: to get the index path.

The following are the scroll positions you can choose from

UICollectionViewScrollPositionNone
UICollectionViewScrollPositionTop
UICollectionViewScrollPositionCenteredVertically
UICollectionViewScrollPositionBottom
UICollectionViewScrollPositionLeft
UICollectionViewScrollPositionCenteredHorizontally
UICollectionViewScrollPositionRight
like image 168
MJN Avatar answered Oct 04 '22 00:10

MJN