我正在尝试将文件夹结构包含到我的 xcode 项目中,其中包含 html、css、js 和图像,如下所示:
htmlcontent
html
test.html
css
test.css
js
test.js
我将文件夹及其子文件夹复制到 xcode,我可以看到那里的 heirachy,但是当我执行以下操作时:
NSString *pathToFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
NSURL *url = [NSURL fileURLWithPath:pathToFile isDirectory:NO];
[_webView loadRequest:[NSURLRequest requestWithURL:url]];
它打印:
/Users/scoota/Library/Application Support/iPhone Simulator/6.0/Applications/8AAC5870-DF24-49BB-BCB8-598C8C0A7C9A/TestApp.app/test.html
有没有办法保留层次结构?我问的原因是我的 html 文件引用了 css,如下所示:
<link rel="stylesheet" type="text/css" href="htmlcontent/test.css" media="screen, projector" />
因此,CSS 未加载。如果我将其更改为以下内容:
<link rel="stylesheet" type="text/css" href="test.css" media="screen, projector" />
它加载了。
有什么想法吗?
最佳答案
将文件添加到 Xcode 项目时,请确保选择“创建文件夹引用”而不是“为文件夹创建组”
但是,这不应该是 ,,/css/test.css 吗?
关于ios - 在 IOS 中保留 html 文件的文件夹层次结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13033507/