问题
I'm having a weird error here. I have an array named __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];
When I NSLog out the content of the array, I get this output:
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;
    };
}
But when I NSLog out NSLog(@"%@", [__ImageData objectAtIndex:0]);, I get this exception:
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:
etc..
I have no idea how to reach an object in this array.. It seemes like the objectAtIndex cant find any indexes, not even index:0, even though there is data inside.. Anyone know how to get it? 
I am using the PhotoScroller-template from Apple, using the CATiledLayer. I think the whole thing is kinda funky, but everybody says we should use this for large images. Anyone have an explanation or a better idea than CATiledLayer for huge images? (8556*7121px).
And why do I get Dictionary-error from the NSArray?
When doing NSDictionary *dict = [__ImageData objectAtIndex:0], I also get the same exception.
Stian.
回答1:
_ImageData is not an array, it is a dictionary.  To display the first element of the dictionary you could do something like:
NSLog(@"%@", [_ImageData objectForKey:@"Item 0"]);
回答2:
I ran into this same issue using an JSON Array. My fix was to convert it to an NSDictionary like so:
[(NSDictionary *)json objectForKey:@"detail"];
Or you could do it like this:
NSDictionary *dict = (NSDictionary *)array;
来源:https://stackoverflow.com/questions/12094550/sigabrt-on-nsdictionary-objectatindex-unrecognized-selector