title: UICollectionView cellForItemAt not called second time
body: <p>I have a project were you login and after that images are loaded from the web into a collectionView. I set number of sections to 1 and the first time i login everything is displayed properly.
  I can see the following order:</p>
  
  <ul>
  <li>numberOfSection      (giving 1 here)</li>
  <li>numberOfItemsInSection 0</li>
  <li>insetForSectionAt</li>
  </ul>
  
  <p>then i have an event when my images are downloaded and i call following code didFinishDownloadingTo</p>
  
  <pre><code>func urlSession(_ session: URLSession, downloadTask: URLSessionDownloadTask, didFinishDownloadingTo location: URL) {
      let url=(downloadTask.currentRequest?.url)?.pathComponents
  
  
      let urlId = (url!.last)!
      let offerIndex = self.downloadIndex[urlId]
      let imageData=try? Data(contentsOf: location)
  
      if imageData != nil &amp;&amp; offerIndex != nil &amp;&amp; self.offers[offerIndex!] != nil /* &amp;&amp; offerIndex! &lt; self.offers.count */ {
          self.stopAutoScrolling()
  
          //Sending to background thread since we see in profile that this takes time and hanging main thread
          DispatchQueue.global(priority: DispatchQueue.GlobalQueuePriority.default).async(execute: {
              self.downloadCache[urlId] = imageData
              self.offers[offerIndex!]!.image = UIImage(data: imageData!)
              self.updateCache()
  
              DispatchQueue.main.async {
                  self.setupDataForCollectionView()
                  self.collectionView?.reloadData()
                  self.startAutoScrolling()
              }
  
          })
  
      }
  
  }
  
  
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -&gt; CGSize {
  
      return self.view.frame.size
  }
  
  func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAt section: Int) -&gt; UIEdgeInsets {
      return UIEdgeInsets(top: -64, left: 0, bottom: 0, right: 0)
  }
  
  override func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      print("section num \(section)")
  
      return carousel.count
  }
  
  override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! EventOfferCell
  
      //LoggingManager.sharedInstance.logInfo("Carousel count %i indexPath %i", carousel.count,indexPath.row)
      if let offer = offerForIndexPath(indexPath) {
          if let offerImage = offer.image {
              cell.imageView.image = offerImage
              cell.activityIndicator.stopAnimating()
              cell.titleLabel.isHidden = true
          }
          else {
              cell.titleLabel.text = offer.title
          }
      }
  
      return cell
  }
  
  func setupDataForCollectionView() {
      carousel.removeAll()
      for (_, offer) in self.offers {
          carousel.append(offer)
      }
      if carousel.count &gt; 1 {
          let firstOffer = carousel.first
          let lastOffer = carousel.last
  
          carousel.append(firstOffer!)
          carousel.insert(lastOffer!, at: 0)
      }
  }
  </code></pre>
  
  <p>After the reloadData i get the following scenario:</p>
  
  <ul>
  <li>numberOfSection      (giving 1 here)</li>
  <li>numberOfItemsInSection 4</li>
  <li>sizeForItemAt</li>
  <li>cellForItemAt is called and I set my images that I want to scroll between</li>
  </ul>
  
  <p>Though <strong>second time</strong> after I logout and the collection view is loaded i get the same scenario though after reloadData when the images are downloaded nothing is happening, no numberOfSection call nothing.
  I have really tried many different solutions but nothing works.
  Since cellForItemAt and sizeForItemAt is not called I get no images displayed the second time i login </p>
  
  <p>I have tried to set numberOfItemsInSection statically to 2 and provide two images statically and that is working since then  sizeForItemAt is called etc</p>
  
  <p>My dataSource and delegate are set in the storyboard to the correct Controller</p>
  
  <p>I am really stuck at this problem so all help is appreciated</p>