7

How to reload UIPageViewController in viewDidAppear?

There, I refresh information from CoreData and I want to updated values when the view appears.

I tried with function reloadInputViews(), but unsuccessfully only when you start to open pages then the information is updated.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Bogdan Bogdanov
  • 882
  • 11
  • 36
  • 79
  • is your "`UIPageViewController`" an "`IBOutlet`" in your view controller? Is your "`UIPageViewController`" subclassed? – Michael Dautermann Dec 06 '14 at 23:28
  • You need to use the `setViewControllers:direction:animated:completion:` function to load the view controllers for the page(s) you want to reload. – pbasdf Dec 06 '14 at 23:30
  • mind helping me out, i have a similar issue. http://stackoverflow.com/questions/29764415/reload-uipageviewcontroller-json-swift – Serge Pedroza Apr 21 '15 at 06:40

1 Answers1

9

If you want to reload the ViewControllers inside the UIPageViewController, just re-set them with:

pageViewController(pageViewController: UIPageViewController, didFinishAnimating finished: Bool, previousViewControllers: [UIViewController], transitionCompleted completed: Bool)

if you are going to update your viewControllers from inside a viewController, you have to call it this way:

override func viewDidAppear(animated: Bool) {
    super.viewDidAppear(animated)
    let viewControllers: [UIViewControllers] = [UIViewController()]
    if let pageViewController = parentViewController as? UIPageViewController {
        pageViewController.setViewControllers(viewControllers, direction: .Forward, animated: true, completion: nil)
    }
}
Devran Cosmo Uenal
  • 6,055
  • 2
  • 26
  • 29
  • `override func viewDidAppear(animated: Bool) { super.viewDidAppear(animated) self.setViewControllers(pageViewController, direction: .Forward, animated: true, completion: {}) }` prints an error `ViewController does not have a member named setViewControllers` – Bogdan Bogdanov Dec 07 '14 at 00:17
  • this `if` never executes – Bogdan Bogdanov Dec 07 '14 at 01:48
  • Mind helping me out here, I have a similar http://stackoverflow.com/questions/29764415/reload-uipageviewcontroller-json-swift – Serge Pedroza Apr 21 '15 at 06:40