gpt4 book ai didi

swift - webViewDidStartLoad 和 webViewDidFinishLoad 不工作

转载 作者:行者123 更新时间:2023-11-28 14:35:58 24 4
gpt4 key购买 nike

我正在尝试检查 WebView 是否正在加载以及是否已完成加载,当我尝试搜索它时,这就是我得到的结果,但是它似乎不起作用是因为我做错了什么或者他们更改代码吗?我确实为 Web View 设置了委托(delegate),所以我认为问题不在于委托(delegate)。

@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var activity: UIActivityIndicatorView!

override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stackoverflow.com")

let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func webViewDidStartLoad(_ webView: UIWebView){
print("Webview started Loading")
}

func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}

最佳答案

您需要使您的类符合 UIWebViewDelegate 并将 webView 的管理委托(delegate)给您的类:

class YourClass: UIViewController, UIWebViewDelegate {
@IBOutlet weak var webView: UIWebView!
@IBOutlet weak var activity: UIActivityIndicatorView!

override func viewDidLoad() {
super.viewDidLoad()
let url = URL(string: "https://stackoverflow.com")

//!!!!!!!
webView.delegate = self
//!!!!!!!
let urlRequest = URLRequest(url: url!)
webView.loadRequest(urlRequest)
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func webViewDidStartLoad(_ webView: UIWebView){
print("Webview started Loading")
}

func webViewDidFinishLoad(_ webView: UIWebView) {
print("Webview did finish load")
}
}

关于swift - webViewDidStartLoad 和 webViewDidFinishLoad 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50876415/

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