0

我在排序 nsarray 时遇到问题。nsarray 填充了核心数据:

  NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription
                               entityForName:@"ReactionInfo" inManagedObjectContext:managedObjectContext];
[fetchRequest setEntity:entity];
NSError *error;
self.scoreInfos_arr = [managedObjectContext executeFetchRequest:fetchRequest error:&error];


for (ReactionInfo *info in self.scoreInfos_arr) {
    debug(@"%@ - %f",info.player,info.score);             
}

你看到我得到了球员的名字和分数。我的目标是在表格视图中显示分数,但当然它们应该是数字排序的。

我没有找到关于如何排序这个 NSArray 的解决方案(就是 self.scoreInfos_arr)

我希望有人能帮助我。

4

1 回答 1

1

使用 NSSortDescriptor

[fetchRequest setSortDescriptors: [NSArray arrayWithObject:
                                       [[[NSSortDescriptor alloc] initWithKey:@"score"
                                                                    ascending:YES] autorelease]]];
于 2012-06-27T18:43:57.290 回答