title: Using PageControl in a CollectionViewCell on a ViewController
body: <p>I'm trying to display a PageControl for images in a CollectionViewCell.</p>
  
  <p>Everything seems to be working correctly - the number of pages is correct and even the print(currentPage) shows the correct index; however, the PageControl doesn't show the correct current page.</p>
  
  <p>EncounterDetailViewController.swift</p>
  
  <pre><code>class EncounterDetailViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate, UIScrollViewDelegate {
  
  // MARK: - Properties
  var selectedEncounter: Encounter?
  var currentPage = 0
  
  // MARK: - UICollectionViewDataSource
  func numberOfSections(in collectionView: UICollectionView) -&gt; Int {
      return 1
  }
  
  func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
      return (selectedEncounter?.images.count)!
  }
  
  func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -&gt; UICollectionViewCell {
      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "imageCell", for: indexPath) as! EncounterCollectionViewCell
  
      cell.imageView.sd_setImage(with: URL(string: (selectedEncounter?.images[indexPath.row])!))
      cell.pageControl.numberOfPages = (selectedEncounter?.images.count)!
      cell.pageControl.currentPage = self.currentPage
  
      return cell
  }
  
  // MARK: - ScrollView Delegate Method
  func scrollViewDidScroll(_ scrollView: UIScrollView) {
      let pageWidth = scrollView.frame.width
      self.currentPage = Int((scrollView.contentOffset.x + pageWidth / 2) / pageWidth)
      print(currentPage)
  }
  
  }
  </code></pre>
  
  <p>EncounterCollectionViewCell.swift</p>
  
  <pre><code>class EncounterCollectionViewCell: UICollectionViewCell {
  
      // MARK: - Outlets
      @IBOutlet weak var imageView: UIImageView!
      @IBOutlet weak var pageControl: UIPageControl!
  
  }
  </code></pre>