2

我正在使用核心数据并尝试UITableViewNSMutableSet. 我有两个实体,TeamsPlayers。在我的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

我想知道填充按玩家名字排序的表格视图的最佳方法是什么。

4

1 回答 1

0

从核心数据存储中填充表的最佳方法是使用NSFetchedResultController. 但这并不能解决您遇到的问题,问题是您尝试设置cell.textLabel.textNSManagedObject,这是行不通的。你可以设置

cell.textLabel.text = Player.someStringAttribute
于 2012-07-05T03:24:19.027 回答