开发者

Why is my UIWebView showing lots of HTML instead of the local file?

I have a "download manager" integrated into my iPhone App which allows the user to save a webpage online to their documents folder on their device to view off开发者_JAVA技巧line and locally. This works perfectly, except the files show with lots of HTML code rather than what they should look like.

Here's the UITableView with files: http://cl.ly/3D2g0o3C3a302J243D3v Here's the UIWebView with the HTML in it instead of the usual webpage: http://cl.ly/2s1h3H3D1c1t3y1J2G0W

I'm loading my UIWebView like this (looks all fine?):

NSURL *url = [[NSURL alloc] initFileURLWithPath:documentsDirectory]; 
NSURLRequest *req = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:req];

Why is this happening and what can I do to rectify this?


Use this line of code my friend,

[WebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"]isDirectory:NO]]];

and here is a code that i use before:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *appSettingsPath = [documentsDirectory stringByAppendingPathComponent:@"index.html"];

now, you have the file path in your document directory. then:

[webview loadHTMLString:SiteString baseURL:[NSURL fileURLWithPath:appSettingsPath]];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜