Hello all and thanks for your time.
I would like to know How I can build a list of all the cell data selected and write that into an array which I then write into a .plist
I just want to keep adding to the “*selecedArray” object from the selected cells.
When I “NSLog” my data the current code below shows that I over write the last selection therefore… I end up with the last selected cell. Hope that makes sense.
Thanks Ahab.
NSMutableArray *selectedArray = [[NSMutableArray alloc] init];
NSMutableDictionary *New_myData = [[NSMutableDictionary alloc] initWithCapacity:1];
NSString *selected = [prodArray objectAtIndex:indexPath.row];
[selectedArray addObject:selected];
[New_myData setValue:selectedArray forKey:@"SelctedPrds"];
NSLog( @"data from BuildString %@", New_myData);
Is this code in your
tableView:didSelectRowAtIndexPath:method?If so, you’re creating a new array
NSMutableArray *selectedArrayevery time the user selects a row, which means it will always have a single item (i.e. the row that was just selected).You need an array in a higher scope. Try setting up
selectedArrayas an instance variable/property on the class. You’ll need to initialize the array in the class’sinitmethod. Then when the user selects a row, add it to the array and it will hold onto its state properly.You may also need to code to release the memory (if you’re not using ARC) and perhaps some way to clear out the array (if there’s a “clear” or “deselect all” kind of option in your app)