2012-09-05 120 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

只是踢我走進取景器和重命名的文件的一個完全相同的名稱,並將其加載。然後我做了其他 - 只是將它們重命名爲相同的名稱。我看了一下,在文件名之前或之後沒有任何奇怪的字符或空格。所以現在它們都可以很好地加載到模擬器中的數組中。我仍然沒有想出爲什麼。

相關問題