I have a UICollectionView
which displays images from an online database. I first load 10 images, and then when the user scrolls to the bottom of the UICollectionView
I load another 10 images in the background and refresh the view. I accomplish this using the following method :
func collectionView(collectionView: UICollectionView, willDisplayCell cell: UICollectionViewCell, forItemAtIndexPath indexPath: NSIndexPath) {
if (self.localFeedContent != nil && self.localFeedContent!.count > 0) {
if indexPath.item == (self.localFeedContent!.count-1) {
loadMoreData()
}
}
}
Now this works perfectly fine, however there is no indication to the user that the process is complete and unless he scrolls further down, he won't notice that new content has been added. I would like to implement a UIRefreshControl
which will be attached to the bottom of the UICollectionView
and mimic the same exact behaviour as the regular UIRefreshControl
on top of the screen does. I have already implemented one on top of the screen, however I am not sure how to do this at the bottom as well.
You don't need to implement a
UIRefreshControl
on the bottom, just implement ascrollView
method to do some action when the scroll reach the bottom of screen. You can use some flags inside the conditional to more get a more specific action.I've written something similar - I return another cell at the bottom that just shows a
UIActivityIndicator
. So your datasource would be something similar to:Or instead of calling
loadMoreData()
inwillDisplayCell
, you could call it in thecellForItemAtIndexPath
method (when you're returning the newUICollectionViewCell
with aUIActivityIndicator
). Either could work.