2009-11-30 93 views
0

我有一个UIWebView(webview),其中有一个链接。我已经为这个类实现了UIWebViewDelegate。当我点击链接时,页面加载,但我得到一个错误。为什么UIWebView链接点击错误?

- (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

任何想法的区别是什么?

+0

你告诉我们你有错误,但没有发布错误?什么是错误? – 2009-11-30 07:38:49

+0

对不起。刚刚更新了这个问题。 – 4thSpace 2009-11-30 07:49:46

回答

0

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

+0

一旦url被分割在下划线上,你如何将更新后的url返回给uiwebview? – 4thSpace 2009-11-30 14:45:40

+0

您可以通过使用stringByAddingPercentEscapesUsingEncoding转义所有字符,即给出错误,在您的url:NSUTF8StringEncoding方法 – 2009-11-30 16:45:28

+0

谢谢。我如何让页面自动缩小以适合视图?现在,一旦页面加载,它是巨大的,所以你只能看到它的一部分。 – 4thSpace 2009-11-30 17:39:52