iPhone在单独目录中引用资源 [英] iPhone Referring to Resources in Separate Directories

查看:106
本文介绍了iPhone在单独目录中引用资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此问题讲述了如何在资源路径中创建目录。创建后,如何引用这些目录?

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在单独目录中引用资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆