UIPageViewController with WKWebView

谁都会走 提交于 2019-12-25 01:24:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!