xcode 在 UIWebView 中单击时 shouldStartLoadWithRequest 不加载链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4708904/
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
shouldStartLoadWithRequest not loading links when clicked on in UIWebView
提问by Rob Segal
I've started using shouldStartLoadWithRequest and been encountering puzzling behaviour as I understand things. In it's most simplest form I've tried the following...
我已经开始使用 shouldStartLoadWithRequest 并且在我理解的事情中遇到了令人费解的行为。以最简单的形式,我尝试了以下...
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
return YES;
}
With the side effect of when I click on HTML links the links do not load new pages in the UIWebView. Very likely I am not understanding something completely here. Any feedback/help would be greatly appreciated.
当我点击 HTML 链接时,链接不会在 UIWebView 中加载新页面的副作用。很可能我在这里没有完全理解某些东西。任何反馈/帮助将不胜感激。
回答by Mihir Mehta
Two Possible reason
两个可能的原因
1>either you have not set the delegate
Set delegate your webview to your class
i.e in viewDidLoad
method
1>要么你没有设置委托将你的webview委托给你的类,即在viewDidLoad
方法中
webView.delegate = self;
(if webView is taken in xib file you need to set the delegate from sib file)
(如果 webView 是在 xib 文件中获取的,则需要从 sib 文件设置委托)
2>your class does not implement UIWebViewDelegate protocol i.e. in your interface's declaration you haven,t declare it like this
2>你的类没有实现 UIWebViewDelegate 协议,即在你的接口声明中你没有这样声明
@interface RootViewController : UIViewController<UIwebViewDelegate>