title: Update text label when UICollectionView cell is presented
body: <p>I have a <code>UICollectionView</code> (A), where I can scroll between different cells horizontally, which is itself in a <code>CollectionViewCell</code> (B).</p>
  
  <p>I am defining some layout in the <code>CollectionViewCell</code> (B) and would like one text label to be updated when a certain cell in (A) is presented.</p>
  
  <p><strong>What I have, in (B)</strong></p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
  
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: friendRequestCellId, for: indexPath) as! FriendRequestCell
  
      cell.user = userFriendRequests?[indexPath.row]
      nameLabel.text = cell.user?.first_name
  
      return cell
  }
  </code></pre>
  
  <p><strong>Issue</strong></p>
  
  <p>The text in the <code>nameLabel</code> gets populated incorrectly with the <code>user.first_name</code> as it does not update suitably when scrolling through the cells in (A), i.e. the cell presented in (A) and the <code>user.first_name</code> displayed in (B) often don't match. I am pretty sure doing it like this just updates the text when the cells in (A) get dequeued, which is of course not what I want.</p>
  
  <p>What could be the correct way to implement the desired behavior ? </p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Found out about the nifty <code>collectionView(_:willDisplay:forItemAt:)</code> method which almost solves the problem, but this changes the label as soon as the next cell starts to display. This means that when the Collection View is loaded, if I scroll just a bit forth and back, the <code>nameLabel</code> contains the <code>firstName + " " + lastName</code> of the second cell while the first one is displayed. Looking for some kind of "didDisplay" method but haven't found something like it.</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
  
      guard let firstName = userFriendRequests?[indexPath.row].first_name, let lastName = userFriendRequests?[indexPath.row].last_name else {
          return
      }
  
      nameLabel.text = firstName + " " + lastName
  }
  </code></pre>
  
  <p>PS: Still a Swift noob, also thought about using some kind of delegation but a bit unclear on how that would play out in this case</p>