我正在使用核心数据并尝试UITableView
用NSMutableSet
. 我有两个实体,Teams和Players。在我的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];
}
在另一个视图控制器上,我试图用该团队的球员填充一个表格视图。为此,我正在执行以下操作
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
我想知道填充按玩家名字排序的表格视图的最佳方法是什么。