Skip to content

Instantly share code, notes, and snippets.

@kaiinui
Created June 18, 2014 07:33
Show Gist options
  • Save kaiinui/f26907d88e1a7f69ef34 to your computer and use it in GitHub Desktop.
Save kaiinui/f26907d88e1a7f69ef34 to your computer and use it in GitHub Desktop.
Infinite Scroll with UICollectionView in Swift
import UIKit
class ViewController: UICollectionViewController, UICollectionViewDataSource, UICollectionViewDelegate {
override func collectionView(collectionView: UICollectionView!, numberOfItemsInSection section: Int) -> Int {
...
}
override func collectionView(collectionView: UICollectionView!, cellForItemAtIndexPath indexPath: NSIndexPath!) -> UICollectionViewCell! {
...
}
override func scrollViewDidScroll(scrollView: UIScrollView) {
let offsetY = scrollView.contentOffset.y
let contentHeight = scrollView.contentSize.height
if offsetY > contentHeight - scrollView.frame.size.height {
loadSomeDataAndIncreaseDataLengthFunction()
self.collectionView.reloadData()
}
}
}
@User2004
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment