简体   繁体   English

UIWebViewDelegate问题

[英]UIWebViewDelegate Problems

I have a UIWebView set up in Interface Builder with the delegate set to File's Owner. 我在Interface Builder中设置了UIWebView,并将委托设置为File's Owner。 I have webViewShouldStartLoad, webViewDidFinishLoad, webViewDidStartLoad, and webViewDidFailLoadWithError set up with NSLogs inside to see if they are working. 我在里面设置了NSLogs的webViewShouldStartLoad,webViewDidFinishLoad,webViewDidStartLoad和webViewDidFailLoadWithError来查看它们是否正常运行。 webViewShouldStartLoad works perfectly, but the other three only work on the initial load. webViewShouldStartLoad可以完美运行,但是其他三个仅在初始加载时有效。 if I click a link to go to another page, the other three don't work. 如果我单击链接转到另一页,则其他三个不起作用。 All the webpages load fine, but I cant get any of the webview delegate functions other than webViewShouldStartLoad to workAnyone have any ideas why this might be? 所有网页都可以正常加载,但是除了webViewShouldStartLoad之外,我无法使用任何其他webview委托函数来工作任何人都不知道为什么会这样?

Is File's Owner the View Controller responsible for the UIWebView? File的所有者是View Controller负责UIWebView的吗?

Make sure it is. 确保是。

Second, I prefer to set the delegate in code. 其次,我更喜欢在代码中设置委托。 I takes away any mystery for novice developers. 对于新手开发人员,我不带任何神秘色彩。 Interface Builder can be unclear at times, especially if you're unsure what the links look like in code. Interface Builder有时可能不清楚,尤其是当您不确定代码中的链接是什么样时。 Remember, Interface Builder just saves you from writing certain code; 请记住,Interface Builder只是使您免于编写某些代码。 everything you do in IB can be done in code. 您在IB中所做的一切都可以用代码完成。

Try this in the View Controller, usually in viewDidLoad: 在View Controller中尝试此操作,通常在viewDidLoad中:

self.webView.delegate = self;

(You don't HAVE to call 'self', I like to for reasons outside this thread) (您不必称自己为“自我”,出于这个线程之外的原因,我喜欢这样)

Be sure that View Controller which owns the UIWebView implements UIWebViewDelegate in the header file. 确保拥有UIWebView的View Controller在头文件中实现UIWebViewDelegate。

UPDATE Also, this from the dev site: 更新此外,这来自开发人员站点:

"Important: You should not embed UIWebView or UITableView objects in UIScrollView objects. If you do so, unexpected behavior can result because touch events for the two objects can be mixed up and wrongly handled." “重要:您不应该将UIWebView或UITableView对象嵌入UIScrollView对象中。如果这样做,则可能会导致意外行为,因为这两个对象的触摸事件可能会混合并错误处理。”

Have you done this? 你做完了吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM