我一直在这个小时,并找不到问题。 我有一个分数数组,我在核心数据模型中保存在游戏结束时。当我重新回到高分视图 - 控制我从核心数据加载的分数,并使用下面的函数,其中得分阵列是一个NSMutableArray与我的10个高分核心数据排序NSMutableArray奇怪的结果
[self.scoresArray sortUsingFunction:firstNumSort context:@selector(totalScore)];
//function to sort high scores in the array
NSInteger firstNumSort(id str1, id str2, void *context) {
static int counter = 0;
NSLog(@"counter = %d", counter);
counter++;
//NSLog(@"should be sorting");
int num1 = [str1 totalScore];
int num2 = [str2 totalScore];
if (num1 > num2) {
NSLog(@"%@ is greater than %@", num1, num2);
return NSOrderedAscending;
}
else if (num1 < num2){
NSLog(@"%@ is less than %@", num1, num2);
return NSOrderedDescending;
}
else {
NSLog(@"%@ is the same as %@", num1, num2);
return NSOrderedSame;
}
}
这始终将最后得分排序的数组保存后无论其值如何进入列表顶部?奇怪的是,当我重新启动我的应用程序时,相同的功能将所有分数以正确的降序排列,这正是我想要的,但显然我不希望用户必须重新启动应用才能看到以正确顺序显示的分数。任何人都可以请点亮一下发生了什么?
非常感谢
朱
什么类型是str1和str2? – Eiko 2010-06-30 15:59:32