views:

370

answers:

1

I have a UIWebView (webview) with one link in it. I have implemented UIWebViewDelegate for this class. When I click the link, the page loads but I get an error.

- (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'&gt;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);
}

Error output is:

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

However, this link works fine: http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Classes/NSTimer%5FClass

Any ideas on what the difference is?

A: 

see http://stackoverflow.com/questions/1528060/uiwebview-error-while-loading-url, it seems that the UIWebView is not capable of processing "strange characters", although I do not think that the _ is a strange character.

Vincent Osinga
Once the url is split on the underscore, how do you give the updated url back to the uiwebview?
4thSpace
you can escape all characters, that give errors, in your url by using the stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding method
Vincent Osinga
Thanks. How can I get the page to automatically shrink so it fits the view? Right now, once the page loads, it's huge so you can only see some of it.
4thSpace
That is unfortunately not up to you, but to the builder of the webpage...
Vincent Osinga