2012-06-27 71 views
0

我有一個問題,排序nsarray。 的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是)

我希望有人能幫助我。

回答

1

使用NSSortDescriptor

[fetchRequest setSortDescriptors: [NSArray arrayWithObject: 
             [[[NSSortDescriptor alloc] initWithKey:@"score" 
                    ascending:YES] autorelease]]]; 
+0

感謝,這就是一個簡單的方法來做到這一點 - 謝謝你真多:-) – H3rrVorr4g3nd