Multiple WKwebkit views in a single view controller not working

拟墨画扇 提交于 2020-04-30 11:03:29

问题


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

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