2009-11-30 87 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

相關問題