本文介绍了单个视图控制器中的多个 WKwebkit 视图不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法加载我的子视图.我将它们定义为弱 WKWebKit
插座.如果我执行 view = tickerView
或 view = graphView
,它可以工作,但它只加载其中之一.我想加载两者.我该怎么做?
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)
}
推荐答案
如果您已经将 outlet webView 连接为弱连接,请不要添加为 subView.
Don't add as subView if you are already connect outlet webView as weak.
我在故事板中添加了两个带有约束的 WkWebKit 视图
,以编程方式加载 URL 并且它工作正常,因此使用此代码您可以加载两个 WKWebKit 视图.
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.
示例代码:
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
}
}
这篇关于单个视图控制器中的多个 WKwebkit 视图不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!