此问题讲述了如何在资源路径中创建目录。创建后,如何引用这些目录?
This question tells how one can create directories in your resources path. Once created, how does one reference these directories?
我已经创建了一个带有用于内部页面结构的html目录,现在我想从中加载index.html文件html目录。因此,我需要它的文件路径。
I have created an html directory with a structure for my internal pages, now I want to load the index.html file from the html directory. Thus, I'll need the file path to it.
我可以使用:
NSString *filename = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html"];但是,如果目录结构中包含两个index.html文件,会发生什么呢?它是否找到第一个?引用可以更具体吗?
But what happens if there are two index.html files contained in the directory structure? Does it just find the first one? Can the referencing be more specific?
小测试项目这里如果您想看一下就不起作用
Little test project here that is not working if you want to take a look
推荐答案如果您有一条复制到资源束中的路径,则在查找资源时也应引用该路径,例如:
If you have a path that is copied into your resource bundle, you also should reference the path when looking for the resource like:
NSString *filename = [[NSBundle mainBundle] pathForResource:@"html/index" ofType:@"html"];编辑:
您显然不能仅仅在资源名称中包含目录(我相信您可以在UIImage上进行其他类似的调用,例如 imageNamed:)。工作电话是:
You cannot apparently just include the directory in the resource name (I believe you can for other similar calls like "imageNamed:" on UIImage). The working call is:
NSString *helpFile = [[NSBundle mainBundle] pathForResource:@"index" ofType:@"html" inDirectory:@"html"];更多推荐
iPhone在单独目录中引用资源
发布评论