开发者

iPhone - NSDictionary sorting based on values [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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜