Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

luke3

macrumors newbie
Original poster
Jun 6, 2012
23
0
Hi I am trying to save data into core data and having some trouble... I have a Team Entity and a Player Entity The Team Entity is set up as a one to many relationship with the Player Entity... on my "NewTeamViewController" there are two sections, in the second section is where you add players to the team. In the section header there is a button to add a new player... When that button is pressed a new cell appears with three textFields, each with default text in them (not placeholder text) then I am adding the new player to a MutableSet that will be added as the teams players. The tableview is using a custom cell (which is where the three textFields live)
The team saves correctly, except I am unable to save the data from the three text fields in the player cell. It just saves the default text in the cell for the player.
I am not sure how or where to give the data from the newly added cell to the newly added player object.
Here is some code..


Code:
-(void)saveButtonWasPressed {

self.team =[NSEntityDescription insertNewObjectForEntityForName:@"Team" inManagedObjectContext:self.managedObjectContext];

team.schoolName = _schoolName.text;
team.teamName = _teamName.text;
team.season =  _season.text;
team.headCoach = _headCoach.text;
team.astCoach = _assistantCoach.text;

player.firstName = cell.playerFirstName.text;
player.lastName = cell.playerLastName.text;
player.number = cell.playerNumber.text; 

[self.team addPlayers:_tempSet];

[self.managedObjectContext save:nil];
[self.navigationController popViewControllerAnimated:YES];    
}
//////////////////////////////////////////////////////////////////////////////////////////////////


-(void)addPlayerButton {

player = (Player *)[NSEntityDescription insertNewObjectForEntityForName:@"Player" 
                                                            inManagedObjectContext:self.managedObjectContext];

[_tempSet addObject:player]; 

[self.tableView reloadSections:[NSIndexSet indexSetWithIndex:1]  withRowAnimation:UITableViewRowAnimationFade];     
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.