2

iOS 6では、このコードブロックは正常に機能します。

- (NSString*)cLocalImageName
{
     [self willAccessValueForKey:@"cLocalImageName"];
     NSString*pathToImage;
     if ([self.cIsUserCreated boolValue]) {
         pathToImage =  [self primitiveValueForKey:@"cLocalImageName"];
     }else{
         pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@".png"];
     }
     [self didAccessValueForKey:@"cLocalImageName"];
     return pathToImage;
}

つまり、この行は常に正しいファイルパスを返します。

 pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@".png"];

ただし、iOS 5では、その行は常にnilを返すため、代わりに次のように呼び出す必要があります。

 pathToImage = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",[self primitiveValueForKey:@"cLocalImageName"]]];

誰かが私にこれがiOS5の問題である理由について何か洞察を与えることができますか?

私が除外したこと:

•[selfprimitiveValueForKey:@"cLocalImageName"]はnilを返していません。

•.pngオブジェクトは、アプリがビルドされると、コンパイルされた.appパッケージに実際に存在します。

4

1 に答える 1

12

この行にすべきではありません:

pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@".png"];

これである:

pathToImage = [[NSBundle mainBundle] pathForResource:[self primitiveValueForKey:@"cLocalImageName"] ofType:@"png"];

于 2012-10-30T21:15:42.550 に答える