使用swift写一个wkwebview

查了很多都跑不通,还是官网的可以,很多资料的xcode版本或者swift版本都和你本地的不一样,直接照搬代码好多都跑不通。还是要看官方文章。

直接谷歌搜索swift wkwebview文章

wkwebview

//
//  ViewController.swift
//  iosWebview
//
//  Created by xxx on 2019/11/18.
//  Copyright © 2019年 xxx  All rights reserved.
//

import UIKit
import WebKit

class ViewController: UIViewController, WKUIDelegate {
    
    var webView: WKWebView!
    
    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, typically from a nib.
        
        let myURL = URL(string:"https://www.baidu.com/")
        let myRequest = URLRequest(url: myURL!)
        webView.load(myRequest)
    }
    
}


运行报错了,

2019-11-18 15:17:43.757325+0800 iosWebview[10620:183192] Unknown class ViewController in Interface Builder file.
2019-11-18 15:17:43.758366+0800 iosWebview[10620:183192] Failed to set (keyPath) user defined inspected property on (UIViewController): [<UIViewController 0x7fd5a1d0acd0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key keyPath.

第一个报错,勾选一下就行了
解决方案
第二个报错,发现没影响,页面照常加载出来了,后面有空在追

运行结果

运行结果

源代码

源码链接

发布了190 篇原创文章 · 获赞 37 · 访问量 30万+

猜你喜欢

转载自blog.csdn.net/sufubo/article/details/103123181