问题
I am not able to load my sub views. I define them as weak WKWebKit
outlets.
if i do view = tickerView
or view = graphView
, it works, but it only loads one of them. I want to load both. How would i do this?
override func loadView() {
tickerView = WKWebView()
tickerView.navigationDelegate = self
self.view.addSubview(tickerView)
graphView = WKWebView()
graphView.navigationDelegate = self
self.view.addSubview(graphView)
}
回答1:
Don't add as subView if you are already connect outlet webView as weak.
I add two WkWebKit View
in storyboard with constrains, programmatically load URL and it's work properly so using this code you can load both WKWebKit Views.
Example code :
import UIKit
import WebKit
class ViewController: UIViewController,WKNavigationDelegate{
@IBOutlet weak var webView1: WKWebView!
@IBOutlet weak var webView2: WKWebView!
override func viewDidLoad() {
super.viewDidLoad()
webView1.load(URLRequest(url: URL(string: "https://www.google.com/")!))
webView1.navigationDelegate = self
webView2.load(URLRequest(url: URL(string: "https://www.youtube.com/")!))
webView2.navigationDelegate = self
}
}
来源:https://stackoverflow.com/questions/59062568/multiple-wkwebkit-views-in-a-single-view-controller-not-working