【问题标题】:Why does UIWebView link click error out?为什么 UIWebView 链接点击错误?
【发布时间】:2009-11-30 07:36:32
【问题描述】:

我有一个带有一个链接的 UIWebView (webview)。我已经为这个类实现了 UIWebViewDelegate。当我单击该链接时,页面会加载,但出现错误。

- (void)viewDidLoad {
[super viewDidLoad];
webview.delegate = self;
NSString *html = @"<html> \n"
"<head> \n"
"</head><body> \n"
"<p><b><a href='http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class/Reference/NSTimer.html'>click here</a></b></p> \n"
"</body> \n"
"</html>";
[webview loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] bundlePath]]];}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
NSLog(@"the error is: %@", error);
}

错误输出是:

the error is: Error Domain=WebKitErrorDomain Code=101 UserInfo=0x3814410 "Operation could not be completed. (WebKitErrorDomain error 101.)"

但是,此链接可以正常工作:http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer_Class

有什么不同的想法吗?

【问题讨论】:

  • 您告诉我们您有错误但没有发布错误?什么错误?
  • 对不起。刚刚更新了问题。

标签: iphone cocoa-touch uiwebview


【解决方案1】:

UIWebView: Error while loading URL,UIWebView 似乎无法处理“奇怪的字符”,虽然我不认为 _ 是一个奇怪的字符。

【讨论】:

  • 一旦url被下划线分割,如何将更新后的url返回给uiwebview?
  • 您可以使用 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding 方法在您的 url 中转义所有给出错误的字符
  • 谢谢。如何让页面自动缩小以适合视图?现在,一旦页面加载,它就很大,所以您只能看到其中的一部分。
猜你喜欢
  • 2011-07-11
  • 2013-07-31
  • 1970-01-01
  • 1970-01-01
  • 2014-02-25
  • 1970-01-01
  • 2012-02-02
  • 2014-02-02
  • 2011-06-08
相关资源
最近更新 更多