how to preload next and previous view in UipageViewController swift

Viewed 2929

As after a lot of search and RND and after many different code implementation the issue of delay in swipe was not resolved so i guess preload the next and previous view controllers will resolve my issue of swipe delay.

how to load next and previous view before swipe. Didnot find the solution after long rnd and search

2 Answers

You can call nextController.loadViewIfNeeded() and prevController.loadViewIfNeeded(), after showing visible controller!

pageViewController?.setViewControllers([controller], direction: direction, animated: animated, completion: { (_) in
    if let nextController = /*Find it*/ {
       nextController.loadViewIfNeeded()
    }
    if let prevController = /*Find it*/ {
       prevController.loadViewIfNeeded()
    }
})

You must find nextController and prevController in the code, I think that is easy.

Related