Tuesday, 6 August 2013

iOS NSMutableArray suddenly obtains more values

iOS NSMutableArray suddenly obtains more values

I'm loading data (json) from a backend into my UITableView - so far so
good. Data will be passed to to a DetailView after the user selected a
specific row - works fine.
BUT...when I return to the UITableView from the DetailView suddenly the
Array which obtains different IDs more values:
So I'm saving each ID in the NSMutableArray like this:
//Dictionary
NSDictionary *GroupDataDictionary = [self.groupDataArray
objectAtIndex:indexPath.row];
//save groupID to array atIndex: current indexPath.row
[self.groupIDArray insertObject:[GroupDataDictionary valueForKey:@"id"]
atIndex:indexPath.row];
This works. I implemented a test to display each GroupID saved in the
NSMutableArray
GroupID in NSMutableArray : 2
GroupID in NSMutableArray : 3
GroupID in NSMutableArray : 4
GroupID in NSMutableArray : 5
GroupID in NSMutableArray : 6
GroupID in NSMutableArray : 7
But the third time i return from the DetailView to my TableView I'll get
something like this:
GroupID in NSMutableArray : 2
GroupID in NSMutableArray : 2
GroupID in NSMutableArray : 3
GroupID in NSMutableArray : 4
GroupID in NSMutableArray : 5
GroupID in NSMutableArray : 6
GroupID in NSMutableArray : 7
This goes on like this until the complete Array obtains ID 2.
What is going on?
Thx for help!

No comments:

Post a Comment