I'm faced with a small problem. I have a UITableView with 2 sections: folders and individual posts (inks). Posts are saved into a NSMutableArray and folders are an array of arrays that contain posts. When you hit the Edit button, check mark boxes appear on each cell that allow each post to be checked. Once an item is checked, it is removed from the inks array and moved into a temporary array. After you select which folder you'd like to move the posts to, the items from the temporary array are copied into one of the folder arrays. The reason I'm using a temporary array to transfer the items is incase the user unchecks an item so that this way it's not removed from the actual array.
-(IBAction)checkMarkSelected:(id)sender
{
if(numberTimesChecked%2==0) { //even times, check
[appDelegate.inksToFolder addObject:[appDelegate.inks objectAtIndex:[sender tag]]];
[tempArray removeObjectAtIndex:[sender tag]]; //tempArray is initialized with the contents of appDelegate.inks in the viewDidAppear method, so its just a duplicate
}
else //odd times, no check
{
[appDelegate.inksToFolder removeObjectAtIndex:[sender tag]];
[tempArray addObject:[appDelegate.inks objectAtIndex:[sender tag]]];
}
numberTimesChecked++; }
-(IBAction)moveToFolderPressed:(id)sender
{
NSMutableArray *arrayOfInks=[appDelegate.folders objectAtIndex:[sender tag]];
[arrayOfInks addObjectsFromArray:appDelegate.inksToFolder];
[appDelegate.folders replaceObjectAtIndex:[sender tag] withObject:arrayOfInks];
}
So the problem I am facing is what to do if the user hits the check box more than once. If the user presses it an even amount of times, this means the checkmark is present, and if an odd amount of times, then there is no checkmark, and these items should not be touched. However, when an item is checked and say this item is at index 4 in the inks array, this item is moved to the tempArray at index 0. If it is then unchecked, how will it know where to remove the item from in the tempArray? So if I check index 4 then index 2 then index 7 then uncheck index 4, it will attempt to remove the object from index 4 from the inksToFolder array, but that index doesn't exist. Does anyone know a solution, or even a better way to implement this whole thing?