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”时
@"/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. 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资源的相对路径资料......但是没有一个能够工作。我怎样才能解决这个问题?我想对所有图像资源说@“a.png”(尤其是我在另一个应用程序中执行此操作...我直接使用示例代码)。
So what is that magical setting?
那神奇的环境是什么?
Thanks!
2 个解决方案
#1
7
+[UIImage imageNamed:]
will look in your app bundle's resources to find the image. If you add an image to Xcode it will be default be added to the resource copy phase of your project. 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.
+ [UIImage imageNamed:]将查看您的应用包的资源以查找图像。如果将图像添加到Xcode,它将默认添加到项目的资源复制阶段。如果你想确保它被复制到你的应用程序包中,请查看Xcode编辑器左侧的列表,在目标下你将看到你的应用程序名称,在那之下你将看到几个构建阶段,只要一个.png出现在“复制包资源”阶段你应该好好去。
#2
1
You need to make sure a.png is imported as a resource into xCode. If you have done that then referencing it as just "a.png" should work.
您需要确保将a.png作为资源导入xCode。如果你已经这样做,那么引用它只是“a.png”应该工作。
#1
7
+[UIImage imageNamed:]
will look in your app bundle's resources to find the image. If you add an image to Xcode it will be default be added to the resource copy phase of your project. 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.
+ [UIImage imageNamed:]将查看您的应用包的资源以查找图像。如果将图像添加到Xcode,它将默认添加到项目的资源复制阶段。如果你想确保它被复制到你的应用程序包中,请查看Xcode编辑器左侧的列表,在目标下你将看到你的应用程序名称,在那之下你将看到几个构建阶段,只要一个.png出现在“复制包资源”阶段你应该好好去。
#2
1
You need to make sure a.png is imported as a resource into xCode. If you have done that then referencing it as just "a.png" should work.
您需要确保将a.png作为资源导入xCode。如果你已经这样做,那么引用它只是“a.png”应该工作。