【发布时间】:2013-08-05 06:33:57
【问题描述】:
我已尽力寻找将 NSMutableDictionary 添加到 NSMutableArray 的答案。不幸的是,他们都要求我使用“[allValues]”,这不是我想要的。
问题来了,
在头文件中,我定义了,
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”仅获得 [[[[self rssParser]rssItems]objectAtIndex:i]header] 的最后一个值。而且我确信 mutableDictionary5 获得了所有值,因为我在代码末尾添加了以下内容,
NSLog(@"mutableDictionary5 values=%@",[mutableDictionary5 allValues]);
它打印标题的所有值。
我知道它不应该是 setvalue,但是,我尝试使用 [mutableDictionary5 allValues]、“addobjects”、“allkeys”。他们不工作。我应该怎么做才能让 NSMutableArray arData 以“title”为键添加所有 title 值?谢谢。
对不起,我的英语不好,不是我的母语。
【问题讨论】:
-
简单地使用
[arData addObject:[mutableDictionary5 objectForKey:@"title"]];有什么问题 -
它给出字符串响应,并在使用 objectforkey 传递数据时给出错误
标签: iphone nsmutablearray nsmutabledictionary object-code