开发者

Can't load html file to webview

开发者 https://www.devze.com 2022-12-11 16:36 出处:网络
Here is my code : NSString *path1 = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@\"NewSouthWales.html\"];

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 show开发者_如何学Pythons page source code.

Please help ... Thanks in advance


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]]];


NSString *path1 = [[NSBundle mainBundle] pathForResource:@"NewSouthWales" ofType:@"html"];
    NSURL *baseurl = [NSURL fileURLWithPath:path1];

    NSData *pathData = [NSData dataWithContentsOfFile:path1];
//Check first if the file path's data is captured. if true, load the html on the web view

   if (pathData) {
        [webView loadData:pathData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:baseurl];
  }
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号