0

同様の質問がいくつ行われたかはばかげていますが、私には何の助けにもなりません。

これが私のコードです:

        BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat: @"Flags/%@.jpg", countr.Name]];
        if (exists) {
            NSLog(@"exist");
        }

Flagsその中にファイルが入った名前のグループがあります。このグループをルートに入れてみましたが、コードが機能しませんでした。次に、それをResourcesに入れてみましたが、ファイルパスに「Resources /」の両方があり、それがないと機能しませんでした。

4

1 に答える 1

2

以下のコードを使用できます。

NSString *exists = [[NSBundle mainBundle] pathForResource:@"%@", countr.Name ofType:@"jpg"];

//This line checks if anything was stored in the string exists. Nothing would be stored in it if there was no file that existed.
if(exists == nil){ 
    NSLog(@"Doesn't exist");
}
else{
    NSLog(@"Exists!");
}

お役に立てれば!

于 2012-06-08T06:05:12.707 に答える