Sort JSON NSDictionary for UITableView
I am using TouchJSON to retrieve info for my app and put it in a dictionary. 开发者_高级运维I would like to be able to sort it by values like difficulty and rating. How would I go about this? I have included my .m file. Thanks, enbr http://pastie.org/1091334
You can probably use NSSortDescriptor
to sort the array of dictionaries with specified keys. So, for example, the following can sort the array by the key "ratings" in each dictionary:
NSSortDescriptor *ratingsSortDescriptor = [[[NSSortDescriptor alloc] initWithKey:@"ratings" ascending:YES] autorelease];
rows = [rows sortedArrayUsingDescriptors:[NSArray arrayWithObject:ratingsSortDescriptor]];
精彩评论