2012-09-05 128 views
0

我有我的资源文件夹中的“hit_circle_19.png”图像“hit_circle_0.png”,但由于某种原因,此代码从未通过测试“发现”令人讨厌的是我有完全相同的功能在另一种方法工作只是在它下面。并且这些文件中有“复制包资源”为什么这不为这些图像找到正确的pathForResource?

NSMutableArray *hitCircle = [[NSMutableArray alloc]init]; 
for (int i = 0; i < 20; i++) { 

    NSString *name = [NSString stringWithFormat:@"hit_circle_%i", i]; 
    NSString *filePath= [[NSBundle mainBundle] pathForResource:name ofType:@"png"]; 

    if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]){ 
     NSLog(@"file %@ was found", filePath); 
    } else{ 
     NSLog(@"%@ not found", filePath); 
    } 
} 
+0

你确定文件名吗? iOS文件系统区分大小写。 –

回答

0

我几乎可以肯定你找错了子目录,你需要使用类似:

NSString *filePath= [[NSBundle mainBundle] pathForResource:name ofType:@"png" inDirectory:@"Hit_Circles"]; 

或者,如果它只是在Documents目录,你可以使用此,然后附加您的文件名:

NSString* documentsPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]; 
+0

我试过子目录字符串 - 仍然是“空” – frankie

0

只是踢我走进取景器和重命名的文件的一个完全相同的名称,并将其加载。然后我做了其他 - 只是将它们重命名为相同的名称。我看了一下,在文件名之前或之后没有任何奇怪的字符或空格。所以现在它们都可以很好地加载到模拟器中的数组中。我仍然没有想出为什么。

相关问题