我已经尽了全力来搜索答案的NSMutableDictionary添加到NSMutableArray里。不幸的是,他们都要求我使用“[allValues]”,这不是我想要的。只有的NSMutableDictionary的最后的值被添加到NSMutableArray的
这里是问题,
在头文件中,我定义,
NSMutableArray *arData;
而在M档,
arData = [[NSMutableArray alloc] init];
NSMutableDictionary *mutableDictionary5 = [[NSMutableDictionary alloc]init];
for (i=0;i<[[[self rssParser]rssItems]count];i++)
{
Lat = [[[[[self rssParser]rssItems]objectAtIndex:i]lat] doubleValue];
Lng = [[[[[self rssParser]rssItems]objectAtIndex:i]lng] doubleValue];
// Creates a marker in the center of the map.
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(Lat, Lng);
marker.title = [[[[self rssParser]rssItems]objectAtIndex:i]header];
[mutableDictionary5 setObject:marker.title forKey:@"title"];
[arData setValue:[mutableDictionary5 valueForKey:@"title"] forKey:@"title"];
}
的 “arData” 只得到了最后一个值的[[[[自我rssParser]的RSSItems] objectAtIndex:我]头]。而我肯定mutableDictionary5得到,因为我已经把下面的代码末尾的所有价值,
NSLog(@"mutableDictionary5 values=%@",[mutableDictionary5 allValues]);
它打印出标题的所有值。
我的理解不应该是setValue方法,但是,我试图用[mutableDictionary5 allValues], “addobjects”, “allkeys”。他们不工作。我该如何让NSMutableArray arData以“title”作为关键字添加标题的所有值?谢谢。
对不起我的英语不好,这不是我的母语。
简单地使用'[arData addObject:[mutableDictionary5 objectForKey:@“title”]];' –
它给出了字符串响应,并在给objectforkey传递数据时给出错误 –