title: How to connect UIPageControl to UICollectionView (Swift)
body: <p>I'm currently using a UICollectionView to display 3 images (each image spans the entire cell). I also have a UIPageControl that I placed on top of the UICollectionView. What I want to happen is to have the UIPageControl show the number of images (which in this case is 3), and also which image the user is currently viewing. The effect I am trying to go for is that of the Instagram app. </p>
  
  <p>The way that I am currently using to achieve this effect is by placing the updating of the UIPageControl within the UICollectionView's <code>willDisplay</code> function, like so:</p>
  
  <pre><code>func collectionView(_ collectionView: UICollectionView, willDisplay cell: UICollectionViewCell, forItemAt indexPath: IndexPath) {
      pictureDots.currentPage = indexPath.item
  }
  </code></pre>
  
  <p>This manages to correctly hook up the paging effect between the collection view and page control. However, the problem that I have is that the UIPageControl starts off saying the user is on the third image, even though it is displaying the first image. </p>
  
  <p>Does anyone know why this is happening and how to fix this problem?</p>