title: Using UIPageViewController with swift and multiple view controllers
body: <p>I'm trying to utilize a <code>UIPageViewController</code> in a Swift app with multiple view controllers. I have 2 view controllers on my storyboard (<code>firstViewController</code> and <code>secondViewController</code>) that are both embedded in their own navigation controllers. They have storyboard identifiers "<code>FirstViewController</code>" and "<code>SecondViewController</code>". I also have a page view controller on my storyboard with <code>identifierPageView</code> controller and set the navigation to horizontal and transition style to scroll in the attributes inspector. <code>FirstViewController</code> is the root view controller of the app</p>
  
  <p>I want <code>firstViewController</code> to be the first page of the page view controller so I have written its class like so:</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class FirsttViewController: UITableViewController, UIPageViewControllerDataSource, UIPageViewControllerDelegate  {
  
      override func viewDidLoad() {
  
          let pageViewController: PageViewController = self.storyboard.instantiateViewControllerWithIdentifier("PageViewController") as PageViewController
  
          pageViewController.delegate = self
  
          var viewControllers: [UIViewController] = [self]
  
          pageViewController.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
          pageViewController.view.frame = CGRectMake(0, 0, self.view.frame.width, self.view.frame.height)
  
          self.addChildViewController(pageViewController)
          self.view.addSubview(pageViewController.view)
          pageViewController.didMoveToParentViewController(self)
  
  
      }
      func pageViewController(pageViewController: UIPageViewController!, viewControllerAfterViewController viewController: UIViewController!) -&gt; UIViewController! {
  
  
          let secondViewController: SecondViewController = self.storyboard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController
  
  
          return secondViewController
      }
  
      func pageViewController(pageViewController: UIPageViewController!, viewControllerBeforeViewController viewController: UIViewController!) -&gt; UIViewController! {
  
          return nil
      }
  
      func presentationCountForPageViewController(pageViewController: UIPageViewController!) -&gt; Int {
          return 2
      }
  
      func presentationIndexForPageViewController(pageViewController: UIPageViewController!) -&gt; Int {
          return 0
      }
  }
  </code></pre>
  
  <p>the file for <code>SecondViewController</code> looks like this:</p>
  
  <pre><code>import Foundation
  import UIKit
  
  class SecondViewController: UITableViewController, UIPageViewControllerDataSource {
  
      func pageViewController(pageViewController: UIPageViewController!, viewControllerAfterViewController viewController: UIViewController!) -&gt; UIViewController! {
  
          return nil
      }
  
      func pageViewController(pageViewController: UIPageViewController!, viewControllerBeforeViewController viewController: UIViewController!) -&gt; UIViewController! {
  
          let firstViewController: FirstViewController = self.storyboard.instantiateViewControllerWithIdentifier("FirstViewController") as FirstViewController
          return firstViewController
      }
  
  }
  </code></pre>
  
  <p>However, when I run my app it doesn't seem to have a page view controller. It just shows <code>firstViewController</code> and that's it. No dots, no pages, etc. Anyone know whats wrong? I've found a couple of Objective-C tutorials but they all cover using one view controller for all the pages and have a root view controller that is not a page in the <code>pageView</code> so they weren't too much help. I was hoping it was going to be like using a <code>tabBarController</code> where you just click and drag to the view controllers but thats not the case unfortunately. like I said I've not worked with one of these before so I'm sort of lost.</p>
  
  <h2>update:</h2>
  
  <p>following iiFreeman's suggestion, I subclassed <code>UIPageViewController</code> and made it the root in my storyboard file. below is the subclass</p>
  
  <pre><code>import Foundation
  import UIKit
  class PageViewController: UIPageViewController {
  
      override func viewDidLoad() {
  
          let startingViewController = self.storyboard.instantiateViewControllerWithIdentifier("FirstViewController") as FirstViewController
  
          self.dataSource = startingViewController
          var viewControllers: [UIViewController] = [startingViewController]
  
          self.setViewControllers(viewControllers, direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
  
  
  
      }
  
  }
  </code></pre>
  
  <p>However now the app just hangs on a black screen and eventually Xcode loses connection to the simulator. I'm not really sure what's up.</p>