Iphone – Can’t load html file to webview

iphone

Here is my code :

NSString *path1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"NewSouthWales.html"];

NSURL *pageURL = [NSURL fileURLWithPath:path1];
//URL Requst Object
NSURLRequest *requestObj = [NSURLRequest requestWithURL:pageURL];

//Load the request in the UIWebView.
[self.webView loadRequest:requestObj];

I am getting output in my webview as :
like

……..

instead of giving me proper look of that file it shows page source code.

Please help …
Thanks in advance

Best Answer

First prefer pathForRessource ofType

pathNSString *path1 = [[NSBundle mainBundle] pathForResource:@"NewSouthWales" ofType:@"html"];

And then if the file is local why send a request ? Just use :

NSString *html = [NSString stringWithContentsOfFile:path1 encoding:NSUTF8StringEncoding error:nil];
[self.webView loadHTMLString:html baseURL:[NSURL fileURLWithPath:[[NSBundle mainBundle]bundlePath]]];
Related Topic