简体   繁体   English

如何让我的iPhone应用程序找到我的图像?

[英]How do I make my iPhone app find my images?

My app crashes when I do the following in the applicationDidFinishLaunching event in the app delegate: 当我在app delegate中的applicationDidFinishLaunching事件中执行以下操作时,我的应用程序崩溃了:

_textures[mytex] = [[Texture2D alloc] initWithImage: [UIImage imageNamed:@"a.png"]];

However when I replace @"a.png" with 但是当我用@"a.png"替换@"a.png"

@"/Users/MyUserName/Desktop/MyProjectFolder/a.png"

everything works fine. 一切正常。 I've experimented with the relative path stuff for the a.png resource... but none of it has worked. 我已经尝试了a.png资源的相对路径资源......但是没有一个能够工作。 How can I fix this? 我怎样才能解决这个问题? I'd like to just say @"a.png" for all the image resources (esp. since I did this in another app... where I was working directly with sample code). 我想对所有图像资源说@"a.png" (特别是我在另一个应用程序中执行此操作...我直接使用示例代码)。

So what is that magical setting? 那神奇的环境是什么?

Thanks! 谢谢!

+[UIImage imageNamed:] will look in your app bundle's resources to find the image. +[UIImage imageNamed:]将查看您的应用包的资源以查找图像。 If you add an image to Xcode it will be default be added to the resource copy phase of your project. 如果将图像添加到Xcode,它将默认添加到项目的资源复制阶段。 If you want to make sure it is being copied into your app bundle look at the list on the left side of your Xcode editor, under targets you will see your app name there, under that you will see several build phases, so long as a.png appears in the "Copy Bundle Resources" phase you should be good to go. 如果你想确保它被复制到你的应用程序包中,请查看Xcode编辑器左侧的列表,在目标下你会看到你的应用程序名称,在那之下你会看到几个构建阶段,只要a.png出现在“复制包资源”阶段你应该好好去。

You need to make sure a.png is imported as a resource into xCode. 您需要确保将a.png作为资源导入xCode。 If you have done that then referencing it as just "a.png" should work. 如果你已经这样做,那么引用它只是“a.png”应该工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM