title: Get ParentViewController from pageViewController
body: <p>I have a page-based application, consisting of collectionViews within each ViewController. I then have an viewController coming off the barButton on the pageView which leads to an add page for the user to add their data. I am trying to find a way to determine what the source view controller was so that I can append and reload the correct ViewController. Below is my UIPageView and AddSubject classes:</p>
  
  <p>AddSubject.swift:</p>
  
  <pre><code>import UIKit
  import ChameleonFramework
  
  
  class AddSubjectView: UIViewController {
  
      // collectionView
      @IBOutlet var colourPicker: UICollectionView!
  
      var source = UIViewController()
  
      // source of colours to use in the colour collectionView
      private var data = collectionViewColors.createColor()
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          // gesture recognizer to determine when the user has tapped anywhere but the text field
  
          let tap: UIGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(AddSubjectView.dismissKeyboard))
          view.addGestureRecognizer(tap)
  
  
      }
  
      @IBAction func addPressed(sender: AnyObject) {
  
  
  
  
      }
  
      func addData() {
  
  
  
  
      }
  
      // dismiss keyboard when the user taps away from the text field (called above with #selector)
      func dismissKeyboard() {
  
          view.endEditing(true)
      }
  
  // mandatory methods to display collectionView data in the collectionView
  }
  extension AddSubjectView: UICollectionViewDataSource {
  
      func numberOfSectionsInCollectionView(collectionView: UICollectionView) -&gt; Int {
          return 1
      }
  
      func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -&gt; Int {
  
          return data.count
      }
  
      func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -&gt; UICollectionViewCell {
  
          let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! colourCell
  
  
  
          cell.data = self.data[indexPath.item]
  
  
          return cell
      }
  
  
  
      func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
  
          let cell = collectionView.cellForItemAtIndexPath(indexPath)
  
      }
  
  
  
  }
  </code></pre>
  
  <p>PageViewController.swift:</p>
  
  <pre><code>import UIKit
  import ChameleonFramework
  
  class PageViewController: UIPageViewController,UIPageViewControllerDelegate {
  
      // created for use in the function which determines the title of the navigationBar
      var arrayIndex: Int = 0
      // reference for later function to determine title of navigationBar
      var pageControl = UIPageControl.self
  
      // NSUserDefaults
      let defaults = NSUserDefaults.standardUserDefaults()
  
      // set of viewControllers (based on their storyboard ID)
  
      private(set) lazy var orderedViewControllers: [UIViewController] = {
          return [self.newDayViewController("monday"),
                  self.newDayViewController("tuesday"),
                  self.newDayViewController("wednesday"),
                  self.newDayViewController("thursday"),
                  self.newDayViewController("friday"),
                  self.newDayViewController("saturday"),
                  self.newDayViewController("sunday")
          ]
      }()
  
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
  
          self.setNeedsStatusBarAppearanceUpdate()
          // setting the datasource &amp; Delegate of the UIPageViewController
          dataSource = self
          delegate = self
  
  
  
  
          // set the first viewController for the pageView (monday as it is the first in the set)
  
          if let firstViewController = orderedViewControllers.first {
              setViewControllers([firstViewController],
                                 direction: .Forward,
                                 animated: true,
                                 completion: nil)
  
  
          }
  
      }
  
  
  
  
  
      // function to add view controllers
      // function will only instantiateViewControllers which have a storyboard id containing 'day' e.g Monday, Tuesday, Wednesday
  
      private func newDayViewController(day: String) -&gt; UIViewController {
          return UIStoryboard(name: "Main", bundle: nil) .
              instantiateViewControllerWithIdentifier("\(day)")
      }
  
  
  
  
      // set the navigationBar title to the dayViewController's title
      // if the user is looking at orderedViewControllers[1], then the title of that day is "Tuesday"
  
      func pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool) {
          if (!completed) {
              return
          }
  
  
          if let firstViewController = viewControllers?.first,
              let arrayIndex = orderedViewControllers.indexOf(firstViewController) {
              switch arrayIndex {
              case 0:
                  self.navigationController!.navigationBar.topItem!.title = "Monday"
                  self.navigationItem.title = "Monday"
                  break
  
              case 1:
                  self.navigationController!.navigationBar.topItem!.title = "Tuesday"
                  self.navigationItem.title = "Tuesday"
                  break
  
              case 2:
                  self.navigationController!.navigationBar.topItem!.title = "Wednesday"
                  self.navigationItem.title = "Wednesday"
                  break
  
              case 3:
                  self.navigationController!.navigationBar.topItem!.title = "Thursday"
                  break
              case 4:
                  self.navigationController!.navigationBar.topItem!.title = "Friday"
                  break
  
              case 5:
                  self.navigationController!.navigationBar.topItem!.title = "Saturday"
                  break
  
              case 6:
                  self.navigationController!.navigationBar.topItem!.title = "Sunday"
                  break
  
              default:
                  self.navigationController!.navigationBar.topItem!.title = "Timetable"
  
  
              }
          }
      }
  }
  // Mandatory functions and setup for the pageViewController to work
  
  extension PageViewController: UIPageViewControllerDataSource {
  
  
      func pageViewController(pageViewController: UIPageViewController, viewControllerBeforeViewController viewController: UIViewController) -&gt; UIViewController? {
          guard let viewControllerIndex = orderedViewControllers.indexOf(viewController) else {
              return nil
          }
          let previousIndex = viewControllerIndex - 1
          guard previousIndex &gt;= 0 else {
              return orderedViewControllers.last
          }
          guard orderedViewControllers.count &gt; previousIndex else {
              return nil
          }
          return orderedViewControllers[previousIndex]
      }
  
      func pageViewController(pageViewController: UIPageViewController,
                              viewControllerAfterViewController viewController: UIViewController) -&gt; UIViewController? {
          guard let viewControllerIndex = orderedViewControllers.indexOf(viewController) else {
              return nil
          }
          let nextIndex = viewControllerIndex + 1
          let orderedViewControllersCount = orderedViewControllers.count
  
  
          guard orderedViewControllersCount != nextIndex else {
              return orderedViewControllers.first
          }
          guard orderedViewControllersCount &gt; nextIndex else {
              return nil
          }
          return orderedViewControllers[nextIndex]
      }
      // set number of viewControllers to be presented
      func presentationCountForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
          return orderedViewControllers.count
      }
      func presentationIndexForPageViewController(pageViewController: UIPageViewController) -&gt; Int {
          guard let firstViewController = viewControllers?.first,
              firstViewControllerIndex = orderedViewControllers.indexOf(firstViewController) else {
                  return 0
          }
          return firstViewControllerIndex
      }
  }
  </code></pre>
  
  <p>I was wondering if there is a way to use one addSubject view rather than have to create barButton items for all of the individual viewControllers and link them to their own individual viewController.</p>
  
  <p>Any help would be much appreciated !</p>