Sheik_101 Sheik_101 - 6 months ago 37
iOS Question

How to scroll UICollectionView to the bottom programatically?

I have a

. I want to scroll to the bottom when the view appears. How to do this?

Can someone help me out on this?.
Thanks in advance.


You can use the below code to scroll a UICollectionView programmatically to the bottom

NSInteger section = [self numberOfSectionsInCollectionView:collectionView] - 1;
NSInteger item = [self collectionView:collectionView numberOfItemsInSection:section] - 1;
NSIndexPath *lastIndexPath = [NSIndexPath indexPathForItem:item inSection:section];
[collectionView scrollToItemAtIndexPath:lastIndexPath atScrollPosition:UICollectionViewScrollPositionBottom animated:YES];