iPhone在单独目录中引用资源

编程入门 行业动态 更新时间:2024-10-25 02:24:15
本文介绍了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在单独目录中引用资源

本文发布于:2023-11-12 03:40:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源   目录中   iPhone

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!