xcode webViewDidFinishLoad 不触发称为工作

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24681597/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:12:17  来源:igfitidea点击:

webViewDidFinishLoad not firing called working

xcodeuiwebviewswiftuiwebviewdelegatewebviewdidfinishload

提问by kmiklas

(Swift, iOS8, Xcode6, iPhone/iPad)

(Swift, iOS8, Xcode6, iPhone/iPad)

webViewDidFinishLoadis not being called, is not firing, and is not working.

webViewDidFinishLoad没有被调用,没有触发,也没有工作。

Yes, I have set the containing view controller as the delegate. I CTRL-mousedowned on the UIWebView, dragged up to the little yellow circle representing the view controller, and released. A right-click on the UIWebView object shows that the delegate is set.

是的,我已将包含视图控制器设置为委托。我在 UIWebView 上按住 CTRL 鼠标,拖动到代表视图控制器的黄色小圆圈,然后释放。右键单击 UIWebView 对象显示委托已设置。

Yes, I did implement UIWebViewDelegatein my class declaration, like so:

是的,我确实UIWebViewDelegate在我的类声明中实现了,如下所示:

class Paragraph: UIViewController, UIWebViewDelegate {

Yes, I did restart Xcode, and test on both the simulator and an actual iPhone 4S.

是的,我确实重新启动了 Xcode,并在模拟器和实际的 iPhone 4S 上进行了测试。

The request looks like this:

请求如下所示:

@IBOutlet var paragraph : UIWebView = nil

var r = NSBundle.mainBundle().pathForResource("cheddar", ofType: "htm")
var u = NSURL(fileURLWithPath: r)
paragraph.loadRequest(NSURLRequest(URL: u))

The callback function looks like this:

回调函数如下所示:

func webViewDidFinishLoad() {
    println("webViewDidFinishLoad")
}

回答by kmiklas

I got it. The callback was missing a parameter. For posterity:

我知道了。回调缺少参数。为后人:

func webViewDidFinishLoad(webView: UIWebView!) {

Note the webView: UIWebView!parameter

注意webView: UIWebView!参数

In this case, perhaps even more important, is the way I found the bug. I created an entirely new view controller, and pieced it back together, carefully checking at each step to make sure that I didn't miss anything.

在这种情况下,也许更重要的是我发现错误的方式。我创建了一个全新的视图控制器,并将其拼凑起来,在每一步都仔细检查以确保我没有遗漏任何东西。

When the Intellisense popup showed the function with the parameter, I saw my error.

当 Intellisense 弹出窗口显示带有参数的函数时,我看到了我的错误。

NOTE: In Swift 2.2, the UIWebViewDelegate protocol specifies a different optionality: webView: UIWebView. webView: UIWebView!spawns a warning.

注意:在 Swift 2.2 中, UIWebViewDelegate 协议指定了不同的可选性: webView: UIWebView. webView: UIWebView!产生警告。