UIPageViewController example in Swift

In this video tutorial I demonstrate how to create UIPageViewController in Swift. One of the ways UIPageViewController can be used is to create a little scroll through tutorial for your mobile application and in this video tutorial I am demonstrating just that.

Source code to entire project can be downloaded from here: https://github.com/simplyi/UIPageVIewControllerExample

  • Jean-Baptiste Louazel

    Thank you. Your explanations are very clear. That helped me a lot.

    • @jeanbaptistelouazel:disqus You are most welcome 🙂

  • GöktuÄź Yılmaz

    Here is a good repo for this:

    https://github.com/goktugyil/EZSwipeController

  • Thanks for the video, it was very helpful. I had to change one line possibly due to a new version of Swift.

    self.pageViewController.setViewControllers(viewControllers as [AnyObject], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)

    to:

    self.pageViewController.setViewControllers(viewControllers as? [UIViewController], direction: UIPageViewControllerNavigationDirection.Forward, animated: true, completion: nil)

    • Adam, I am glad it eventually worked! Thank you very much for sharing your code.

  • Goncalo Girao

    Can you help me to do the opposite? I have several view controllers and one pageviewcontroller. I could create this pageview, but now app starts on this one and that’s not what I intend to do. TY

    • sorry, I did not get exactly what you need. Can you explain further?

      • Goncalo Girao

        This tutorial explains how to create a (root view) with PageViewController. I’m creating an app that has several “normal” views and somewhere inside I have a PageViewController. The problem is that the App is starting on the PageViewController instead of normal workflow

        • I see.. Do you know how to make selected view controller on Main.storyboard as Initial View Controller? This is make your app start with that initial view controller. And whenever PageViewController is needed you can then present it to user upon request. Do you know how to presentViewController?

          • Goncalo Girao

            First i Thank you for yor help. Yes I know how to set initial view controller, but dont how to call the pageviewcontroller upon request.

          • You can do it through the widow’s rootViewController. For example if you in AppDelegate you can set a different viewController like this:
            window?.rootViewController = myPageViewController
            If you are on any other view controller than AppDelegate you can first access AppDelegate and then access window object, like so:
            let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate

            appDelegate.window?.rootViewController = myPageViewController

  • robvig

    Thank you so much for this tutorial! I followed what you did line for line but for some reason the page control (dots at the bottom of the page) don’t appear. I’ve compared your code and mine but I can’t find the difference. Can you explain how this UI control gets instantiated?