我正在使用核心数据并尝试使用UITableView
填充NSMutableSet
。我有两个实体,团队和玩家。在我的addTeamsController
我将球员保存到球队如下
-(void)saveButtonWasPressed {
self.team =[NSEntityDescription insertNewObjectForEntityForName:@"Team" inManagedObjectContext:self.managedObjectContext];
Player *newPlayer = (Player *)[NSEntityDescription insertNewObjectForEntityForName:@"Player"
inManagedObjectContext:self.managedObjectContext];
team.schoolName = _schoolName.text;
team.teamName = _teamName.text;
team.teamID = _teamName.text;
team.season = _season.text;
team.headCoach = _headCoach.text;
team.astCoach = _assistantCoach.text;
[self.team addPlayers:_tempSet];
[self.managedObjectContext save:nil];
[self.navigationController popViewControllerAnimated:YES];
}
在另一个viewController上我试图用那些团队玩家填充一个tableview。要做到这一点,我正在做如下
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"firstName" ascending:NO];
NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:sortDescriptor, nil];
_array = [[_team.players allObjects] sortedArrayUsingDescriptors:sortDescriptors];
然后在我的单元格中进行行和索引路径我正在执行以下操作
cell.textLabel.text = [_array objectAtIndex:indexPath.row];
我收到错误
[Player isEqualToString:]: unrecognized selector sent to instance
我想知道用播放器名字填写tableview的最佳方法是什么。
答案 0 :(得分:0)
从核心数据存储中填充表的最佳方法是使用NSFetchedResultController
。但这并不能解决您遇到的问题,问题是您尝试将cell.textLabel.text
设置为NSManagedObject
,但这不起作用。你可以设置
cell.textLabel.text = Player.someStringAttribute