您好我正在尝试将数据保存到核心数据中并且遇到了一些麻烦...我有一个团队实体和一个玩家实体团队实体设置为与玩家实体的一对多关系...在我的“NewTeamViewController”上有两个部分,第二部分是您将球员添加到团队的地方。在部分标题中有一个添加新播放器的按钮...按下该按钮时,会出现一个带有三个文本字段的新单元格,每个文本字段中都有默认文本(不是占位符文本),然后我将新播放器添加到 MutableSet将被添加为球队球员。表格视图正在使用自定义单元格(三个文本字段所在的位置)
团队保存正确,但我无法保存玩家单元格中三个文本字段的数据。它只是将默认文本保存在播放器的单元格中。
我不确定如何或在何处将新添加的单元格中的数据提供给新添加的播放器对象。
这是一些代码...
-(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];
}