Anish Laddha
Anish Laddha

Reputation: 77

Multiple WKwebkit views in a single view controller not working

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)

    }

Upvotes: 0

Views: 967

Answers (1)

Anjali Shah
Anjali Shah

Reputation: 718

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
   }
}

Upvotes: 4

Related Questions