title: Why isn't my PageViewController's DataSource working correctly?
body: <p>I have created a simple storyboard with a PageView Controller.</p>
  
  <p>I will flip between two other View Controllers.</p>
  
  <p>My PageView Controller is a custom class <code>TutorialPageViewController</code>. I've also created a custom DataSource class.</p>
  
  <p>In the DataSource class I expect the <code>pageViewController</code> methods to be called when I attempt to scroll. However this is not the case. I have break points at both methods and they are never called.</p>
  
  <p>The first view controller, "Page the first" comes up correctly, but attempting to scroll around doesn't call the methods, so I can't use them yet (hence they return nil for now).</p>
  
  <p>If I set the DataSource of my view controller to <code>self</code> and put the methods in there, they are called correctly. But I want to move the methods out to a separate class for better code management. So why doesn't it work?</p>
  
  <p>I've tried</p>
  
  <ul>
  <li>Setting my DataSource class to be a <code>UIScrollViewDelegate</code> as well as a <code>UIPageViewControllerDelegate</code> and setting the view controller's <code>delegate</code> to be the DataSource</li>
  <li>The PageView's transition style is <strong>Scroll</strong></li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/t1uaV.png" rel="nofollow"><img src="https://i.stack.imgur.com/t1uaV.png" alt="Storyboard overview"></a></p>
  
  <pre><code>class TutorialPageViewController : UIPageViewController {
      override func viewDidLoad() {
          reset()
      }
  
      func reset() {
          let dataSource = TutorialPageDataSource(storyBoard: storyboard!)
          let content = dataSource.firstContentViewController
  
          self.dataSource = dataSource
  
          self.setViewControllers([content], direction: .forward, animated: true, completion: nil)
      }
  }
  
  class TutorialPageDataSource : NSObject, UIPageViewControllerDataSource {
      private var _storyboard: UIStoryboard
  
      var firstContentViewController: UIViewController
      var secondContentViewController: UIViewController
  
      init(storyBoard: UIStoryboard) {
          _storyboard = storyBoard
          firstContentViewController = _storyboard.instantiateViewController(withIdentifier: "FirstContentViewController")
          secondContentViewController = _storyboard.instantiateViewController(withIdentifier: "FirstContentViewController")
      }
  
      func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -&gt; UIViewController? {
          // break point here never reached
          return nil
      }
  
      func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -&gt; UIViewController? {
          // break point here never reached
          return nil
      }
  }
  </code></pre>