Here's the process I have currently:
1) Tap Add Button 2) Fill out UITextFields in my modal view controller 3) Tap Save Button 4) Data is added to a UITableViewCell 5) Repeat steps 1 - 3 6) New data is added to second cell, but the data in both cells is from the new input
How do I use the same modal view controller to add new data yet retain it in my previous cell(s) and even view the data when I tap on those cell(s)?
Here is my process for going to the modal view controller and adding data to it:
-(IBAction)goToModalView:(id)sender
{
if (self.educationViewController == nil)
{
EducationViewController * temp = [[EducationViewController alloc] initWithNibName:@"EducationViewController" bundle:[NSBundle mainBundle]];
self.educationViewController = temp;
_dataArray = [[NSMutableArray alloc] init];
[_dataArray addObject:temp];
}
else
{
[self addEducation:sender];
}
[self presentViewController:self.educationViewController animated:YES completion:nil];
}
-(IBAction)addEducation:(id)sender
{
[_myTableView beginUpdates];
[_dataArray addObject:self.educationViewController.majorString];
NSArray * paths = [NSArray arrayWithObject:[NSIndexPath indexPathForRow:[_dataArray count]-1 inSection:0]];
[_myTableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationTop];
[_myTableView endUpdates];
}
Here is where I am saving the text in my modal view controller:
-(IBAction)saveData
{
if (_majorTextField.text == nil)
{
_majorString = @"";
}
else
{
_majorString = [[NSString alloc] initWithFormat:@"%@", _majorTextField.text];
[_majorTextField setText:_majorString];
NSUserDefaults * majorDefault = [NSUserDefaults standardUserDefaults];
[majorDefault setObject:_majorString forKey:@"major"];
}
// Other text field code here
[self dismissViewControllerAnimated:YES completion:nil];
}
Any advice is appreciated! Much thanks!