Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - Reload UIPageViewController with new information in viewDidAppear

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.

like image 596
Bogdan Bogdanov Avatar asked Dec 06 '14 23:12

Bogdan Bogdanov


1 Answers

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)
    }
}
like image 113
Devran Cosmo Uenal Avatar answered Oct 27 '22 00:10

Devran Cosmo Uenal