title: Swift UICollectionViewDelegateFlowLayout
body: <p>I am using UICollectionViewDelegateFlowLayout to size the cells in a horizontally scrolling collectionView. </p>
  
  <p>When the ViewController loads the cells in the collectionview are the expected size. However when I scroll the subsequent cells which are shown don't have the correct size applied. </p>
  
  <p>Why is this occuring and how do I ensure all the cells are the correct size?</p>
  
  <p>Correct size on load: </p>
  
  <p><img src="https://i.stack.imgur.com/FJq4y.jpg" alt="on load"></p>
  
  <p>Sizing after scroll: </p>
  
  <p><img src="https://i.stack.imgur.com/AKdLM.jpg" alt="after scroll"></p>
  
  <pre><code>import Foundation
  import UIKit
  import Firebase
  
  class Bundles: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
  
      var bundleArray: [bundleStruct] = []
  
      @IBOutlet var collectionView: UICollectionView!
  
      override func viewDidLoad() {
          self.collectionView.register(UINib(nibName: "BundleCell", bundle: nil), forCellWithReuseIdentifier: "BundleCell")
          collectionView.dataSource = self
          collectionView.delegate = self
      }
  
      override func viewDidAppear(_ animated: Bool) {
          DatabaseClass.getBundles(completion: { result in
              self.bundleArray = result
              self.collectionView.reloadData()
          })
      }
  
    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
      return CGSize(width: collectionView.frame.size.width / 2, height: collectionView.frame.size.height)
      }
  
      func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
          return bundleArray.count * 3
         }
  
      func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
          let cell : BundleCell = collectionView.dequeueReusableCell(withReuseIdentifier: "BundleCell", for: indexPath) as! BundleCell
             return cell
         }
  
  }
  </code></pre>