I am currently trying to implement a simple WKWebView
in a Navigation Page in Xcode using Swift, however, as soon as I switch to the dedicated page the app crashes and throws the following exception:
2021-01-12 16:24:40.981110+0100 SmartMirror[2078:1089320] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[WKWebView view]: unrecognized selector sent to instance 0x11380c400'
I'm also using an activity indicator, which is supposed to show until the page is loaded. This is my code: ThirdViewController.swift
import UIKit
import WebKit
class ThirdViewController: UIViewController, WKUIDelegate {
@IBOutlet var webView: WKWebView!
@IBOutlet var activityIndicator: UIActivityIndicatorView!
override func loadView() {
let webConfiguration = WKWebViewConfiguration()
webView = WKWebView(frame: .zero, configuration: webConfiguration)
webView.uiDelegate = self
view = webView
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let url = URL(string: "http://192.168.178.34:8080/")
let request = URLRequest(url: url!)
webView.load(request)
webView.addObserver(self, forKeyPath: #keyPath(WKWebView.isLoading), options: .new, context: nil)
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if keyPath == "loading" {
if webView.isLoading {
activityIndicator.startAnimating()
activityIndicator.isHidden = false
}else {
activityIndicator.stopAnimating()
activityIndicator.isHidden = true
}
}
}
}
And this is my storyboard, with each page having its own view:
https://i.stack.imgur.com/nFFlH.jpg
Help would be greatly appreciated!
Sincerely,
Lukas
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…