Reputation: 1276
I'm very new to iOS development and Swift. I have a UICollectionView that populates images from the array. My idea is to load initially 10 images and let user scroll to the bottom of the collectionView and then load next 10 images from the array by pressing button 'more' or just automatically. Can you suggest the best way to do it? My code is:
self.searches.insert(results, at: 0)
override func collectionView(_ collectionView: UICollectionView,
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
//1
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier,
for: indexPath) as! CatPhotoCell
// this methods takes one photo from searches array
let flickrPhoto = photoForIndexPath(indexPath: indexPath)
cell.imageView.image = flickrPhoto.thumbnail
cell.cat_name.text = flickrPhoto.title
return cell
}
private extension CatsPhotosCollectionViewController {
func photoForIndexPath(indexPath: IndexPath) -> FlickrPhoto {
return searches[(indexPath as NSIndexPath).section].searchResults[(indexPath as IndexPath).row]
}
}
Upvotes: 0
Views: 394
Reputation: 342
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView){
//step 2 here
}
1.Intially set array count as 10.
2.Increase array count whatever you want inside the above function and reload collectionView.
Upvotes: 1