【问题标题】:Images & CSS not loading in iPhone UIWebView图像和 CSS 未在 iPhone UIWebView 中加载
【发布时间】:2012-09-26 00:03:28
【问题描述】:

当我的 UIWebView 加载我的 index.html 时,CSS 和 JavaScript 引用显示为损坏。下面的代码有什么问题? (我验证了 appUrlString 指向了正确的目录)

NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@""];
NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];

NSString *appUrlString = [NSString stringWithFormat:@"%@/web/", [[NSBundle mainBundle] resourcePath]];
NSURL *appUrl = [NSURL URLWithString:appUrlString];

[_appWebView loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:appUrl];

这是模拟器中显示的内容。

【问题讨论】:

    标签: objective-c html uiwebview


    【解决方案1】:

    你应该使用

    NSURL *appUrl = [NSURL fileURLWithPath:appUrlString];

    因为它是本地文件路径。在您的版本中,“appURL”返回零。 所以没有设置 baseurl。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-05
      • 2011-10-22
      • 1970-01-01
      • 2012-06-19
      • 2016-12-20
      • 2012-08-19
      相关资源
      最近更新 更多