title: Swift CollectionView ReloadData Acting Weird
body: <p>I have a Collection View and a button at the top and that button goes through a list of days. For each day, the collection view should be different and I keep track of changes in a dictionary. However, at each press of the button, I want to reload the data, but it's selecting random cells. When data is reloaded, does it run the cellforitematindexpath over again; if not what exactly does it run?</p>
  
  <p>Here's my CellForItem code:</p>
  
  <pre><code>    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("availability", forIndexPath: indexPath) as! AvailabilityCell
          var tempList: [Int]
          tempList = self.availability[self.days[index]]! as! [Int]
          cell.timeInterval.text = timeIntervals[indexPath.row]
          cell.timePeriod.text = timesForIntervals[indexPath.row]
          cell.timeInterval.textColor = DARK_BLUE
          cell.timePeriod.textColor = DARK_BLUE
          cell.backView.layer.cornerRadius = 10
          cell.backView.layer.masksToBounds = true
          cell.backView.layer.borderColor = DARK_BLUE.CGColor
          cell.backView.layer.borderWidth = 1
          cell.selected = false
      if (tempList[indexPath.row] == 1) {
  
                  cell.timeInterval.textColor = UIColor.whiteColor()
                  cell.backView.backgroundColor = DARK_BLUE
                  cell.timePeriod.textColor = UIColor.whiteColor()
  
      }
          return cell
      }
  </code></pre>
  
  <p>Here's my Cell Did Select/Deselect:</p>
  
  <pre><code> func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
  
          let cell = collectionView.cellForItemAtIndexPath(indexPath) as! AvailabilityCell
          cell.timeInterval.textColor = UIColor.whiteColor()
          cell.backView.backgroundColor = DARK_BLUE
          cell.timePeriod.textColor = UIColor.whiteColor()
          var tempList: [Int]
          tempList = self.availability[self.days[index]]! as! [Int]
          tempList[indexPath.row] = 1
          self.availability[self.days[index]] = tempList
  
      }
  
      func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
          let cell = collectionView.cellForItemAtIndexPath(indexPath) as! AvailabilityCell
          cell.timeInterval.textColor = DARK_BLUE
          cell.backView.backgroundColor = UIColor.whiteColor()
          cell.timePeriod.textColor = DARK_BLUE
          var tempList: [Int]
          tempList = self.availability[self.days[index]]! as! [Int]
          tempList[indexPath.row] = 0
          self.availability[self.days[index]] = tempList
  
      }
  </code></pre>
  
  <p>Here's where data is reloaded:</p>
  
  <pre><code>@IBAction func decreaseDay(sender: AnyObject) {
          index--
          day.text = days[index]
          dispatch_async(dispatch_get_main_queue()) {
              self.timeCollection.reloadData()
          }
          if (index == 0) {
              back.enabled = false
          }
  
          forward.enabled = true
      }
  </code></pre>
  
  <p>Here's  a view of what's happening:
  How it starts:
  <a href="https://i.stack.imgur.com/hk63y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hk63y.png" alt="How it starts"></a></p>
  
  <p>When I reload:
  <a href="https://i.stack.imgur.com/krE40.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/krE40.png" alt="What Happens when I reload"></a></p>