0

ここで奇妙なエラーが発生しています。__ImageData という名前の配列があります。

static NSArray *__ImageData = nil;
NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageData" ofType:@"plist"];
NSData *plistData = [NSData dataWithContentsOfFile:path];
NSString *error; NSPropertyListFormat format;
_ImageData = [NSPropertyListSerialization propertyListFromData:plistData
                                              mutabilityOption:NSPropertyListImmutable
                                                        format:&format
                                              errorDescription:&error];

配列の内容を NSLog アウトすると、次の出力が得られます。

2012-08-23 16:36:35.573 CAT[28814:c07] {
    "Item 0" =     {
        height = 7121;
        name = Map1;
        width = 8556;
    };
    "Item 1" =     {
        height = 7121;
        name = Map2;
        width = 8556;
    };
    "Item 2" =     {
        height = 7121;
        name = Map3;
        width = 8556;
    };
}

しかし、 NSLog out するとNSLog(@"%@", [__ImageData objectAtIndex:0]);、次の例外が発生します。

2012-08-23 16:36:35.573 CAT[28814:c07] -[__NSCFDictionary objectAtIndex:]: 
unrecognized selector sent to instance 0x719d0f0
2012-08-23 16:36:35.574 CAT[28814:c07] *** Terminating app due to uncaught exception 
'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: 
unrecognized selector sent to instance 0x719d0f0'
*** First throw call stack:

等..

この配列内のオブジェクトに到達する方法がわかりません..内部にデータがあるにもかかわらず、objectAtIndexはindex:0でさえもインデックスを見つけることができないようです..誰もそれを取得する方法を知っていますか? を使用して、Apple の PhotoScroller-template を使用していCATiledLayerます。全体的にファンキーだと思いますが、大きな画像にはこれを使うべきだと誰もが言います。巨大な画像について、CATiledLayer よりも優れた説明やアイデアを持っている人はいますか? (8556*7121px)。

NSArray から Dictionary-error が発生するのはなぜですか? を実行するNSDictionary *dict = [__ImageData objectAtIndex:0]と、同じ例外も発生します。

スティアン。

4

2 に答える 2

2

_ImageDataは配列ではなく、辞書です。辞書の最初の要素を表示するには、次のようにします。

NSLog(@"%@", [_ImageData objectForKey:@"Item 0"]);
于 2012-08-23T15:21:47.427 に答える
-1

JSON 配列を使用して、この同じ問題に遭遇しました。私の修正は、次のように NSDictionary に変換することでした:

[(NSDictionary *)json objectForKey:@"detail"];

または、次のようにすることもできます。

NSDictionary *dict = (NSDictionary *)array;
于 2015-03-30T17:12:58.813 に答える