Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在UIWebView中使用HTML和CSS的iPhone本机应用程序_Html_Css_Iphone_Xcode_Uiwebview - Fatal编程技术网

在UIWebView中使用HTML和CSS的iPhone本机应用程序

在UIWebView中使用HTML和CSS的iPhone本机应用程序,html,css,iphone,xcode,uiwebview,Html,Css,Iphone,Xcode,Uiwebview,我在Xcode应用程序包中添加了Html、CSS和图像文件 在我的项目中,我在UIWebView中加载了Html内容,如下所示 NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"html" inDirectory:nil]; NSString *htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8S

我在Xcode应用程序包中添加了Html、CSS和图像文件

在我的项目中,我在UIWebView中加载了Html内容,如下所示

NSString *htmlPath = [[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"html" inDirectory:nil];
NSString *htmlString = [NSString stringWithContentsOfFile:htmlPath encoding:NSUTF8StringEncoding error:nil];

NSURL *Url = [NSURL fileURLWithPath:htmlString];
[self.webView loadHTMLString:htmlString baseURL:Url];
Html文件已加载,但缺少CSS和图像

在我的Html文件中添加CSS和图像,如下所示

<link href="/css/myCss.css" type="text/css" rel="stylesheet"/>

   <img class"icon" alt="" src="/img/icon.png" />


需要帮助来解决此问题。

首先,清除html中文件路径的初始/中的路径,以便:

<link href="css/myCss.css" type="text/css" rel="stylesheet"/>

<img class"icon" alt="" src="img/icon.png" />

我还建议您将html资源放入“www”或“html”文件夹,而不是基本文件夹。

尝试在地址中的第一个“/”之前添加两个点,例如“./css/myCss.css”。@AbhinavGauniyal:刚刚尝试过。但是不工作如果你删除路径中的文件夹,它会工作吗?因此,/css/myCss.css变成myCss.css,/img/icon.png变成icon.png。我相信这就是我前一段时间让它在我的应用程序中工作的原因,尽管文件在文件夹和组中。我也尝试过,但结果是sameOh,对不起,只是检查了代码,我想的应用程序甚至没有使用WebView:/
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myFile" ofType:@"html" inDirectory:nil];

[self.webView loadRequest:[NSURLRequest requestWithURL:url]];