问题
I am having UIPageViewController
displaying the Pdf with the help of WKWebView
. Now I have to preload the Previous and Next PDF Links for Previous and Next Swipe in order to avoid the loading time for the user.
I have tried putting the code when setting up the first ViewController
in the PageViewController
but when I try to swipe the viewDidLoad
is getting called again and then it reloads.
I have implemented the following methods :
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerBefore viewController: UIViewController) -> UIViewController?
func pageViewController(_ pageViewController: UIPageViewController,
viewControllerAfter viewController: UIViewController) -> UIViewController?
回答1:
viewDidLoad
is only called when your view is loaded (it's outlets are initialized) and that happens when your view is going to be shown. Otherwise, iOS system will not call this. If you want iOS system to make a call to this, you can make a hack there like so:
_ = nextVC.view
You will have to do this when you are setting up your list of VCs. What this does is try to access the view
property of next UIViewController
. Due to this get
access, iOS system is forced to initialize your view.
Do remember that this will only initialize your view controller's view. You would need to write the appropriate code so that your PDF also loads along with the view. Do take care of performance as well as you will be initializing 3 VCs and in turn 3 PDFs when you are showing only one.
来源:https://stackoverflow.com/questions/56216968/uipageviewcontroller-with-wkwebview