0

I want to update an mutable array. i have one array "ListArray" with some keys like "desc", "title" on other side (with click of button.) i have one array name newListArray which is coming from web service and has different data but has same keys like "desc" "title". so i want to add that data in "ListArray" . not want to replace data just add data on same keys. so that i can show that in tableview.

..........So my question is how to add data in "ListArray". or any other way to show that data in tableview but replacing old one just want to update the data

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

    }
}

enter image description here

2 Answers 2

1

If you the newListArray is totally different from the oldListArray, then clear the old one, and use the new data to fit it.

Otherwise, you need to merge the two arrays. One way is to check if a data in newListArray is/is not in oldListArray and then decide whether to add it into oldListArray.

When oldListArray is updated, call -reloadData of the tableView.

Sign up to request clarification or add additional context in comments.

2 Comments

this is time consuming , to compare with each object!
but if not pick out the ones already exist in oldList, there may be an issue of repeating data. To pick out things is another story, and of course comparing one by one is not a brilliant way per se. There surely are other ways to do array comparison.
1

If I do not misunderstand your question, you may do something like this:

[listArray addObjectsFromArray:newListArray];
[_tableView reloadData];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.