gpt4 book ai didi

Swift3 UIWebView 委托(delegate)方法未被调用

转载 作者:行者123 更新时间:2023-11-30 12:41:47 25 4
gpt4 key购买 nike

代码:

let termWebView = UIWebView(frame:CGRect(x:0, y:20, width:320, height:400))
termWebView.delegate = self
self.view.addSubview(termWebView)

if let url = URL(string: “http://www.google.co.in”)
termWebView.loadRequest(request)
}


func webView(_ webView: UIWebView, didFailLoadWithError error: Error)
{

}

func webViewDidFinishLoad(webView: UIWebView!)
{

}

我创建了一个简单的 webview 并设置了委托(delegate)。但是委托(delegate)方法没有被调用。代码出了什么问题?任何帮助将不胜感激。提前致谢

最佳答案

试试这个 -

class TouchUIViewController: UIViewController, UIWebViewDelegate {

override func viewDidLoad() {
super.viewDidLoad()

let termWebView = UIWebView(frame:CGRect(x:0, y:20, width:320, height:400))
termWebView.delegate = self
self.view.addSubview(termWebView)
let urlString = "http://www.google.co.in/"

if let url = URL(string: urlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!) {
let request = URLRequest(url: url as URL)
termWebView.loadRequest(request)
}
}

func webViewDidStartLoad(_ webView: UIWebView) {

}

func webView(_ webView: UIWebView, didFailLoadWithError error: Error)
{

}

func webViewDidFinishLoad(_ webView: UIWebView)
{

}
}

关于Swift3 UIWebView 委托(delegate)方法未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42151752/

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