views:

571

answers:

2

the following piece of code which gets successfully built and also seems alright to me but doesn't work... mind that i am new to key value coding and your help will be greatly appreciated... in table view delegate didSelectRowAtIndexPath: method here the categoriesList is a simple table with 5 entries

NSUInteger row = [indexPath row];
NSString *rowString = [categoriesList objectAtIndex:row];
NSString *path = [[NSBundle mainBundle] pathForResource:@"DataBase" ofType:@"plist"];
NSDictionary *rootDict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSArray *allRootKeys = [rootDict allKeys];
NSMutableArray *mutableArray = [[NSMutableArray alloc] init];
for (NSString *name in allRootKeys) {
    NSInteger index = [allRootKeys indexOfObject:name];
    NSDictionary *newDict = [allRootKeys objectAtIndex:index];
    if ([newDict valueForKey:@"Class"] == rowString)
        [mutableArray addObject:[allRootKeys objectAtIndex:index]]; 
}   
NSArray *childControllerArray = [[NSArray alloc] initWithArray:mutableArray];

now i pass childControllerArray to the loadArray ivar of my next controller which gets pushed when any row is selected with the specific array and it displays the contents of that array.... when i delete the above code and pass a simple array of objects to it , It WORKS just fine.... PLEASE HELP

the exception given is:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<NSCFString 0x543eb0> valueForUndefinedKey:]: this class is not key value coding-compliant for the key Class.

A: 

[rootDict allKeys]; //this is an array of NSStrings, NOT Array of NSDictionarys

This code can't work

NSArray *allRootKeys = [rootDict allKeys];
NSDictionary *newDict = [allRootKeys objectAtIndex:index];
oxigen
It can and does work, but the value stored in newDict isn't an NSDictionary of course :P
rpetrich
It works. But it hasn't sense
oxigen
and this: [newDict valueForKey:@"Class"] don't work ))
oxigen
A: 

Thanks a lot for your interest ... i made it work out of some glitch in memory management which caused the trouble... your help really mattered... thank you ...

valiantb