Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Does setting estimatedItemSize on UICollectionViewFlowLayout break UICollectionViewDataSourcePrefetching?

I am creating a UICollectionView with cells of dynamic height and using estimatedItemSize property on UICollectionViewFlowLayout (Apple Docs Reference).

Although, I noticed that once I set the estimatedItemSize property, my prefetchItemsAt method for UICollectionViewDataSourcePrefetching delegate is not getting called.

func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath])

If I don't set estimatedItemSize, prefetching starts working again. Is this known behavior or am I doing something wrong here? Please help.

Sample Code:

class CollectionViewController: UICollectionViewController {

var layout: UICollectionViewFlowLayout = {
    let layout = UICollectionViewFlowLayout()
    let width = UIScreen.main.bounds.size.width
    layout.estimatedItemSize = CGSize(width: width, height: 100)
    return layout
}()

override func viewDidLoad() {
    super.viewDidLoad()
    if #available(iOS 10.0, *) {
        collectionView?.prefetchDataSource = self
    }

    collectionView.collectionViewLayout = layout

    // Register cell classes
    self.collectionView.register(UINib.init(nibName: "CollectionViewCell", bundle: nil), forCellWithReuseIdentifier: reuseIdentifier)
}
}

extension CollectionViewController: UICollectionViewDataSourcePrefetching {

// MARK: UICollectionViewDataSourcePrefetching
func collectionView(_ collectionView: UICollectionView, prefetchItemsAt indexPaths: [IndexPath]) {


    // Fetch more cells
    print("prefetchItemsAt called.")
}
}
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!