iphone - (iphone) imageNamed 当有多个同名文件时?

标签 iphone imagenamed

正如问题所述,当资源目录下有多个具有给定名称的文件时,imageNamed 如何工作?

有没有办法区分两个具有相同名称(但路径不同)的不同文件?

谢谢

最佳答案

任何 Xcode 包中的文件夹都是“组”。也就是说,它们不是实际的目录。这些组中的文件仍然位于 bundle 的根目录中。

因此,应用程序包中不可能有两个(或更多)同名文件。

参见:http://majicjungle.com/blog/?p=123

群组的问题:

The directory structure is lost when it’s copied to the iphone app, and so inside your app bundle is just a big list of all your resources in the base directory. As a result of this, duplicate filenames become an issue. If any files within your directory structure on disk contain the same filename, the build process silently screws everything up. It appears to be ‘first in wins’, with only one of the resources making it into the app bundle. So it’s no good if you have a bunch of different level packages each containing a different ‘Terrain.png’ file.

如果您通过创建文件夹引用来维护目录结构,则可以消除重复文件名的问题。然而,检索文件是个问题。

你可以做的是使用 NSBundle 类:

[[[NSBundle mainBundle]resourcePath]stringByAppendingPathComponent:@"path/to/file.jpg"]

关于iphone - (iphone) imageNamed 当有多个同名文件时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4581666/

相关文章:

iphone - 通过触摸拖动 ImageView

ios - iPhone View 移动动画

iOS 本地化 : Localize views dynamically without messing with the storyboard/nib strings files

iphone - iOS 中 UITableView 的 UISearchDisplayController 框架

iphone - 核心数据 : Transient values dirty object

ios - 应用程序从后台移至前台后,ImageIO_PNG_DATA 继续增长

ios - 覆盖UIImage imageNamed-我有哪些选择?

objective-c - UIImage initWithContentsOfFile 不起作用

ios - 在 UIImage imageNamed 中使用外部图像