我想更新一个可变数组。我有一个数组“ListArray”与一些键像“desc”,“标题”在另一边(单击按钮。)我有一个数组名称newListArray它来自Web服务,并具有不同的数据,但具有相同的键如“ desc“”标题“。所以我想在“ListArray”中添加该数据。不想替换数据只是在相同的键上添加数据。所以我可以在tableview中显示。如何将对象追加到NSMutableArray?
..........所以我的问题是如何在“ListArray”中添加数据。或任何其他方式表明的tableview,但用旧的数据只是想更新数据
NSMutableArray *newListArray = (NSMutableArray*)[[WebServices sharedInstance] getVideoList:[PlacesDetails sharedInstance].userId tokenValue:[PlacesDetails sharedInstance].tokenID mediaIdMin:[PlacesDetails sharedInstance].minId mediaIdMax:[PlacesDetails sharedInstance].maxId viewPubPri:@"Public_click"];
NSDictionary *getNewListDic = [[NSDictionary alloc] initWithObjectsAndKeys:newListArray,@"videoList", nil];
[listVidArray addObject:getNewListDic];
NSArray *keys = [NSArray arrayWithObjects:@"desc",@"url",@"media_id",@"img",@"status",@"media_id_max",@"fb_url",@"title", nil] ;
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
for(int i = 0 ; i < [listVidArray count] ; i++)
{
for(id theKey in keys)
{
// NSMutableArray *item = [NSMutableArray array];
NSLog(@"%@",theKey);
NSLog(@"%@",keys);
[dict setObject:[[[listVidArray objectAtIndex:i]valueForKey:@"videoList"] valueForKey:theKey] forKey:theKey];
// [dict setObject:[newListArray valueForKey:theKey] forKey:theKey];
}
}
这是耗时的,每个对象进行比较! –
但如果没有选择oldList中已存在的那些,则可能存在重复数据的问题。挑选事情是另一回事,当然,一个接一个的比较本身并不是一个好方法。当然还有其他方法可以进行数组比较。 – BabyPanda