我有两个独立的WKWebViewController
。按下按钮时,我先加载第一个WKWebView
,然后加载另一个WKWebView
。
所以我想提前加载另一个WKWebView
。我该怎么办?
两个ViewController中的每个都有WKWebView。
第一个WKWebView
func openSecondScreen(){
let storyboard = uistoryboard(name: "Main",bundle: nil)
let openSecondScreen = storyboard.instantiateViewController(withIdentifier: "SecondWebViewController") as! SecondWebViewController
openSecondScreen.modalPresentationStyle = .overCurrentContext
openSecondScreen.modalTransitionStyle = .crossDissolve
openSecondScreen.delegate = self
self.navigationController?.pushViewController(openSecondScreen,animated: true)
}
第二个WKWebView
@IBOutlet var secondWKWebView: WKWebView!
override func loadView() {
super.loadView()
let images = global.getIndicatorImage()
let animatedImage = UIImage.animatedImage(with: images,duration: 1.0)
self.indicatorImage.image = animatedImage
contentController.add(self,name: "SecondWeb")
config.userContentController = contentController
secondWKWebView = WKWebView(frame: secondWKWebView.frame,configuration: config)
secondWKWebView.uiDelegate = self
secondWKWebView.navigationDelegate = self
view.addSubview(secondWKWebView)
view.addSubview(indicator)
if contentController.userScripts.count > 0 {
contentController.removeAllUserScripts()
}
let localFilePath = Bundle.main.url(forResource: webUrl,withExtension: "html")
let myRequest = URLRequest(url: localFilePath)
secondWKWebView.load(myRequest)
}
我该如何解决这个问题?