title: didSelectItemAt and didDeSelectItemAt from UICollectionView
body: <p>If I use <code>didSelectItemAt</code> in a <code>UICollectionView</code>, I want to change the color of the selected cell. And with <code>didDeselectItemAt</code>, I want to replace the color of the previously selected cell.</p>
  
  <p>It works well before moving. However, moving to the far right will not work properly. Why is this?</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
  
          return 14 
   }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "CalendarCollectionViewCell", for: indexPath ) as! CalendarCollectionViewCell
  
          cell.calendarDayLabel.text = calendar?.twoWeeksDay![ indexPath.row ]
          cell.calendarDateLabel.text = calendar?.twoWeeksDate![ indexPath.row ]
  
          return cell
  
   }
  
  func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  
          let cell = collectionView.cellForItem(at: indexPath) as? CalendarCollectionViewCell
  
  
          cell?.calendarDayLabel.textColor = UIColor( red: 255, green: 0, blue: 0, alpha: 1.0 )
          cell?.calendarDateLabel.textColor = UIColor( red: 255 , green: 255 , blue: 255 , alpha: 1.0 )
          cell?.calendarCircleImageView.isHidden = false
  
          self.selectYear = self.calendar?.twoWeeksYear![ indexPath.row ]
          self.selectMonth = self.calendar?.twoWeeksMonth![ indexPath.row ]
          self.selectDate = self.calendar?.twoWeeksDate![ indexPath.row ]
          self.selectDay = self.calendar?.twoWeeksDay![ indexPath.row ]
  
          self.selectDateTime.text = self.selectYear! + "년 " + self.selectMonth! + "월 " + self.selectDate! + "일 " + self.selectDay!
  
          self.selectDateTime.isHidden = false
  
  }
  
      func collectionView(_ collectionView: UICollectionView, didDeselectItemAt indexPath: IndexPath) {
  
  
          let cell = collectionView.cellForItem(at: indexPath) as? CalendarCollectionViewCell
          cell?.calendarDayLabel.textColor = UIColor( red: 0, green: 0, blue: 0, alpha: 1.0 )
          cell?.calendarDateLabel.textColor = UIColor( red: 0 , green: 0 , blue: 0 , alpha: 1.0 )
          cell?.calendarCircleImageView.isHidden = true
  
   }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/SMBfr.png" rel="noreferrer">enter image description here</a></p>