2012-01-01 37 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"