3 Replies
      Latest reply on Jan 10, 2019 7:11 AM by Claude31
      Tobi218 Level 1 Level 1 (0 points)

        Hi,

         

        I'm working on a project for my university and currently my problem is, that I am not able to get data to the Pages which get called by the UIPageViewController. I've seen some disscussions about it but none of the answers do really cover this topic or show working solutions.

         

        I can get the data to my UIPageViewController class but how do i pass it on to every page attached to it?

         

         

        Thank you!

        • Re: How to get Data to UIPageViewController Pages
          Claude31 Level 8 Level 8 (5,485 points)

          Data should usually be in each page, not in the pageController. PageController "just" holds the dots, keep track of active page, get the array of UIViewControllers…

           

          What data do you want here ?

           

          May look here for a complete example

          h ttp://www.seemuapps.com/page-view-controller-tutorial-with-page-dots

            • Re: How to get Data to UIPageViewController Pages
              Tobi218 Level 1 Level 1 (0 points)

              Makes sense, that the data should only be on the pages. I'm currently passing an instance of a self written data class with the help of segues to all the needed destinations. But there is no segue called when opening the Pages through a PageViewController so I haven't found a way to get data to them.

                • Re: How to get Data to UIPageViewController Pages
                  Claude31 Level 8 Level 8 (5,485 points)

                  I tested this, seems to work OK.

                   

                  In PageViewController, declare the var you want to pass to children (here an Int, but could be anything, as the instance of a self written data class)

                   

                  class PageViewController: UIPageViewController, UIPageViewControllerDelegate, UIPageViewControllerDataSource  {
                  
                      var pageControl = UIPageControl()
                      var testVar: Int = 0

                   

                  In the childView, get this data :

                   

                      override func viewDidLoad() {
                          super.viewDidLoad()
                          let passedData = (self.parent as! PageViewController).testVar
                          print(passedData)