Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reset scroll on UICollectionView

I have a horizontal UICollectionView which works fine and scrolls. When I tap an item I update my data and call reloadData. This works and the new data is displayed in the UICollectionView. The problem is the scroll position doesn't change and it is still viewing the last place. I want to reset the scrolling to the top (Or left in my case). How can I do this?

like image 724
MulletDevil Avatar asked Mar 20 '13 10:03

MulletDevil


2 Answers

You want setContentOffset:. It takes a CGPoint as and argument that you can set to what ever you want using CGPointMake, but if you wish to return to the very beginning of the collection, you can simply use CGPointZero.

[collectionView setContentOffset:CGPointZero animated:YES]; 
like image 190
Mick MacCallum Avatar answered Oct 02 '22 14:10

Mick MacCallum


You can use this method to scroll to any item you want:

- (void)scrollToItemAtIndexPath:(NSIndexPath *)indexPath                 atScrollPosition:(UICollectionViewScrollPosition)scrollPosition                         animated:(BOOL)animated 
like image 38
Nils Hott Avatar answered Oct 02 '22 14:10

Nils Hott