2012-01-01 38 views
0

我有一个NSDictonary对象,我将一组对象设置为一个具有相应键的数组,如下所示。从NSDictonary获取NSArray值

[dictionary setObject: [NSArray arrayWithObjects:@"Player3_Title", @"FirstName", @"LastName", @"Address3", @"SS3", nil] forKey: @"player3_infoKey"]; 

我想要做的就是让这些对象重新回到一个数组中。当我尝试下面的代码时,这是我得到的输出。

stringsMutableArray = [[NSMutableArray alloc] initWithObjects:nil]; 
    [stringsMutableArray addObject:[dictionary objectForKey:@"player3_infoKey"]]; 

NSLog(@"stringsMutableArray has values: %d", [stringsMutableArray count]); 

NSLog(@"stringMutableArray: %@", [stringsMutableArray objectAtIndex:0]); 


OUTPUT: 
2012-01-01 08:50:29.869 test project[1165:f803] stringsMutableArray has values: 1 
2012-01-01 08:50:29.870 test project[1165:f803] stringMutableArray: (
    "Player3_Title", 
    FirstName, 
    LastName, 
    Address3, 
    SS3 
) 

有没有一种方法,我可以得到该键的值到数组中?我想这样做的原因是,我想从该数组中设置文本按钮值的代码中的某处。

FirstNameField1.text = [stringsMutableArray objectAtIndex:1]; 
LastNameField1.text = [stringsMutableArray objectAtIndex:2]; 

回答

1

我觉得你只是想:

stringsMutableArray = [NSMutableArray arrayWithArray:[dictionary objectForKey:@"player3_infoKey"]]; 

如果你不需要它是可变的:

stringsArray = [dictionary objectForKey:@"player3_infoKey"]; 
+0

谢谢!那正是我想要得到的。 – 2012-01-01 14:15:33

0
NSArray *myArray = [dictionary objectForKey:@"player3_infoKey"]; 
[myArray objectAtIndex:0]; // Should return "Player3_Title"