gpt4 book ai didi

ios - WKWebView 未在 swift 4 xcode 10 中初始化

转载 作者:搜寻专家 更新时间:2023-11-01 05:49:22 25 4
gpt4 key购买 nike

谁能帮我理解为什么我的 webView 没有在这里初始化。我收到以下错误,因为 webView 为 nil。

fatal error :在展开可选值时意外发现 nil

我到底缺少什么?

import UIKit
import WebKit


class MemoriesViewController: UIViewController, WKNavigationDelegate {

@IBOutlet weak var webView: WKWebView!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear( animated )

let urlString:String = "https://www.apple.com"
let url:URL = URL(string: urlString)!
let urlRequest:URLRequest = URLRequest(url: url)
webView.load(urlRequest)

}


}

}

为了更清楚地了解实际发生错误的屏幕截图:

enter image description here

最佳答案

将 Webkit.Frameworks 添加到链接的框架和库

enter image description here

然后您可以为 WKWebView 添加 Outlet 并使用您的代码

import UIKit
import WebKit

class MyWebViewController: UIViewController {

@IBOutlet weak var myWV: WKWebView!

override func viewDidLoad() {
super.viewDidLoad()

// Do any additional setup after loading the view.
let urlString:String = "https://www.apple.com"
let url:URL = URL(string: urlString)!
let urlRequest:URLRequest = URLRequest(url: url)
myWV.load(urlRequest)
}


}

关于ios - WKWebView 未在 swift 4 xcode 10 中初始化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54048414/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com