开发者

iPhone - NSDictionary sorting based on values [duplicate]

开发者 https://www.devze.com 2023-04-13 03:04 出处:网络
This question already has answers here:开发者_StackOverflow社区 Closed 10 years ago. Possible Duplicate:
This question already has answers here: 开发者_StackOverflow社区 Closed 10 years ago.

Possible Duplicate:

NSDictionary keys sorted by value numerically?

I'm maintaining the scores of my game in a dictionary. Key will be the name of the user and value will be the score. When displaying the scores in table view, I want to sort the dictionary depending on values so that first item will be top score and last item will be least score. How can this be done?


try this one

NSSortDescriptor *descriptor = 
    [[NSSortDescriptor alloc] initWithKey:@"Score" ascending:YES];
[items sortUsingDescriptors:[NSArray arrayWithObjects:descriptor,nil]];
[descriptor release];
0

精彩评论

暂无评论...
验证码 换一张
取 消