// 數組排序 NSArray *listGroupname = [self.listTeams sortedArrayUsingComparator:^(NSString *n1,NSString *n2) { NSString *val1 = [[NSString alloc]init]; NSString *val2 = [[NSString alloc]init]; if (val1 > val2) { return NSOrderedAscending; } else { return NSOrderedDescending; } }]; // 字典排序 /** dic按key排序而不是按插入時間,因此須要從新排序,獲得排好序的key */ NSArray *sortedKeys = [callDataDic keysSortedByValueUsingComparator:^NSComparisonResult(id obj1, id obj2) { if ([obj1 longLongValue] > [obj2 longLongValue]) { return (NSComparisonResult)NSOrderedAscending; } if ([obj1 longLongValue] < [obj2 longLongValue]) { return (NSComparisonResult)NSOrderedDescending; } return (NSComparisonResult)NSOrderedSame; }];