【问题标题】:How to load FilePath into UIWebbview in iOS?如何在 iOS 中将文件路径加载到 UIWebview 中?
【发布时间】:2014-09-06 23:26:13
【问题描述】:

我想加载我保存在 Core Data 中的 html 文件。 它在 NSString 中得到了类似的东西:

file:///Users/rajeevrajani/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/1339BAA2-127D-4C0C-8C35-5ADA33C46A70/DemoApp.app/0Dosing.html

我想将它加载到 UIWebview 中。 该怎么做?

【问题讨论】:

  • 请在发布问题之前做一些研究。

标签: html ios core-data uiwebview nsurl


【解决方案1】:

在发布问题之前进行研究。

   NSString *htmlFile = //ur file path put here...
    NSString* htmlString = [NSString stringWithContentsOfFile:htmlFile encoding:NSUTF8StringEncoding error:nil];
    [webView loadHTMLString:htmlString baseURL:nil];

它可能对你有帮助,谢谢。

【讨论】:

    【解决方案2】:
    NSString *urlString   = @"//filepath.html";  // get your file path here
    NSURL *webPageURL     = [NSURL URLWithString: urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:webPageURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:0];
    [_webView loadRequest:request]; // _webView is the UIWebView Outlet
    

    【讨论】:

      猜你喜欢
      • 2013-09-14
      • 2013-04-17
      • 1970-01-01
      • 2020-01-22
      • 2019-05-03
      • 1970-01-01
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      相关资源
      最近更新 更多