【问题标题】:Get NSArray values out of NSDictonary从 NSDictionary 中获取 NSArray 值
【发布时间】:2012-01-01 14:04:33
【问题描述】:

我有一个 NSDictonary 对象,我将一组对象设置为一个数组,该数组具有如下对应的键。

[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];

【问题讨论】:

    标签: iphone xcode4 ios4


    【解决方案1】:

    我想你只是想:

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

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

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

    【讨论】:

      【解决方案2】:
      NSArray *myArray = [dictionary objectForKey:@"player3_infoKey"];
      [myArray objectAtIndex:0];  // Should return "Player3_Title"
      

      【讨论】:

        猜你喜欢
        • 2013-08-16
        • 2016-04-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-29
        • 1970-01-01
        • 2015-10-25
        • 1970-01-01
        相关资源
        最近更新 更多