我怎样才能获得相对路径?

时间:2011-05-06 06:06:27

标签: objective-c path warnings relative

我在Objective-c上编程。我有3个文件夹,有3种语言,如en,ru,fr,图片1.png,2.png,3.png。我怎样才能获得相片的相对路径?我该如何在项目中添加这些文件? 我有一些警告。因为我有相同的来源名称。

Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/1.png
Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/2.png
Warning: Multiple build commands for output file /Users/Kate/Documents/XCode_progs/MyProject/build/Debug-iphonesimulator/MyProject/3.png

我的代码不起作用:

CCSprite *button = [CCSprite spriteWithFile:[NSString stringWithFormat:@"%@/1.png", lang]];

1 个答案:

答案 0 :(得分:1)

将您的图片添加到您的项目中,您可以致电:

[[NSBundle mainBundle] pathForResource:@"1" ofType:@"png"];

如果您向此资源添加本地化(png图像)(在XCode 4中选择图像文件并在Utility面板中(右侧)您可以添加不同的本地化),然后在运行时iOS自动选择正确的本地化文件。