2

NSMutableDictionaryオブジェクトとキーを含むこれを取得しました。キーは TemplateID で、オブジェクトは数値です。私の問題は、キーがないとオブジェクトを取り出せないことです。

誰でも助けることができますか?

// Defining stuff...
templateData = [[NSMutableArray alloc] initWithCapacity:0];
[templateData addObjectsFromArray:[[WebXML sharedInstance] extractAddTemplate]];
NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithObjectsAndKeys:templateData, @"TemplateID", nil];

// First method...
NSArray *keys = [dict allKeys];
id aKey = [keys objectAtIndex:0];
id anObject = [dict objectForKey:aKey];

NSLog(@"anObject: %@", anObject);
// In NSLog it says: anObject: TemplateID = <theObject>;
// I just want anObject: <theObject>

// Second method...
for (id key in dict) {
    id anObject = [dict objectForKey:key];

    NSLog(@"anObject: %@", anObject);
    // In NSLog it says: anObject: TemplateID = <theObject>;
    // I just want anObject: <theObject>
}

// Third method...
NSArray  * myArray = [NSArray arrayWithObject:@"TemplateID"];
NSMutableDictionary *anotherDict = [[NSMutableDictionary alloc] initWithObjects:templateData forKeys:myArray];

NSLog(@"anotherDict: %@", anotherDict);
// In NSLog it says: anotherDict: TemplateID = <theObject>;
// I just want anotherDict: <theObject>

// ミッケル

4

0 に答える 0