本帖最后由 枫煠 于 2014-12-31 17:28 编辑
用- - (NSArray *)keysSortedByValueUsingComparator:(NSComparator)cmptr
复制代码- -(NSArray*) getNumberSortKeys:(NSString*)dicKey isASC:(BOOL)isASC{
- return [self keysSortedByValueUsingComparator: ^(id obj1, id obj2) {
- if ([[obj1 objectForKey:dicKey] intValue] > [[obj2 objectForKey:dicKey] intValue]) {
- return (NSComparisonResult)isASC?NSOrderedAscending:NSOrderedDescending;
- }
- if ([[obj1 objectForKey:dicKey] intValue] < [[obj2 objectForKey:dicKey] intValue]) {
- return (NSComparisonResult)isASC?NSOrderedDescending:NSOrderedAscending;
- }
- return (NSComparisonResult)NSOrderedSame;
- }];
- }
复制代码
去抓sort之后的key值的结果,然后再根据键值做一个NSArray出来 我做了一个小Demo你参考看看^^
|