【问题标题】:UiWebView local HTML loading in offline situation离线情况下 UiWebView 本地 HTML 加载
【发布时间】:2016-05-18 16:40:47
【问题描述】:
I'm trying to load local HTML file in offline situation. I found a code here;

http://stackoverflow.com/questions/4645414/how-can-i-load-a-local-html-file-into-the-uiwebview
I'm using Reachability.h of Apple and it is working but I cant load local html file.

我曾经用这个代码加载本地 html

NSString *indexPath = [NSBundle pathForResource:@"index" ofType:@"html" inDirectory:nil]; [mWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:indexPath]]];


https://gist.github.com/FatihDurmus/dba74b42425fe0f71685acec7be12aa8 这是我的控制器代码。

【问题讨论】:

  • 添加一些你尝试过的代码

标签: objective-c uiwebview


【解决方案1】:

您可以使用此代码。它有效。

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"terms_en" ofType:@"html"];
webView.delegate=self;
NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
[webView loadHTMLString:htmlString baseURL:nil];

希望这会有所帮助。 :)

【讨论】:

    猜你喜欢
    • 2017-03-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-06
    相关资源
    最近更新 更多