07-19-2023, 01:34 AM
For **Swift 3** and **multiple sections**
/**
This method scrolls the *UICollectionView* to the last item in the last section
*/
func scrollToLastItem() {
let lastSection = collectionView.numberOfSections - 1
let lastRow = collectionView.numberOfItems(inSection: lastSection)
let indexPath = IndexPath(row: lastRow - 1, section: lastSection)
self.collectionView.scrollToItem(at: indexPath, at: .right, animated: true)
}
/**
This method scrolls the *UICollectionView* to the last item in the last section
*/
func scrollToLastItem() {
let lastSection = collectionView.numberOfSections - 1
let lastRow = collectionView.numberOfItems(inSection: lastSection)
let indexPath = IndexPath(row: lastRow - 1, section: lastSection)
self.collectionView.scrollToItem(at: indexPath, at: .right, animated: true)
}