如何从NSMutableArray访问值

时间:2013-02-12 15:32:11

标签: objective-c nsmutablearray

我在didSelectRowAtIndexPath:方法中有一个NSMutableArray:

[self.somethingSelected addObject:[self.arrayFromTable objectAtIndex:indexPath.row]];

此self.somethingSelected(NSMutableArray)的输出如下。如何从以下输出中仅访问id值?

我希望self.somethingSelected存储“11,9,21 ......”而其他值都没有像title等...

(
    {
        id = 11;
        title = Title0;
    },
    {
        id = 9;
        title = Title1;
    },
    {
        id = 21;
        title = Title2;
    },
)

我试过了:

[self.somethingSelected addObject:[self.arrayFromTable objectAtIndex:indexPath.row] objectForKey:@"id"];

但我想我可能会混淆NSDictionary和NSMutableArray。

1 个答案:

答案 0 :(得分:1)

如果arrayFromTable拥有NSDictionaries而不是你尝试的应该工作,但你错过了'['& ']'。它应该是:

    [self.somethingSelected addObject:[[self.arrayFromTable objectAtIndex:indexPath.row] objectForKey:@"id"]];