Sheik_101 Sheik_101 - 1 year ago 140
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.

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download