I have a UIPageViewController with several pages and when swiping through them, everything works well. The PageViewController automatically pre-loads the neighboring pages of the current one to ensure smooth scrolling (I have UIPageViewControllerTransitionStyle.Scroll
)
Additionally I can also jump to a specific page by entering a number. The problem is, when I jump to a certain page programmatically, the PageViewController doesn't seem to also pre-load neighboring pages, so when I start swiping from the page I just jumped to, there is a half-second delay, before the PageViewController loads the next ViewController so it can be displayed.
I used this answer to jump to pages: https://stackoverflow.com/a/18602186/5461994
and transferred it to Swift:
weak var pvcw = pvc
pvc.setViewControllers([page], direction: UIPageViewControllerNavigationDirection.Forward, animated: true) { finished in
if let pvcs = pvcw {
dispatch_async(dispatch_get_main_queue(), {
pvcs.setViewControllers([page], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
})
}
}
My question is: how can I get the UIPageViewController to pre-load the neighboring pages of a page I just jumped to, just like it automatically does during swiping?
P.S.: I have the same problem on app launch. When I initialize my PageViewController and set the first visible page like this:
pvc.setViewControllers([firstPage], direction: UIPageViewControllerNavigationDirection.Forward, animated: false, completion: nil)
I also have this delay when swiping to the second page the first time. Any help is appreciated!