2013-11-01 36 views
0

我有一个类叫做userResults看起来像这样:排序包含数组的NSMutableArrray?

#import <Foundation/Foundation.h> 

@interface userResults : NSObject 

@property (nonatomic, strong) NSString *resultsMix; 
@property (nonatomic, strong) NSNumber *resultsSaving; 
@property (nonatomic, strong) NSNumber *resultsBlendComponent1; 
@property (nonatomic, strong) NSNumber *resultsBlendComponent2; 
@property (nonatomic, strong) NSNumber *resultsTotalProtein; 
@property (nonatomic, strong) NSNumber *resultsPricePerPound; 
@property (nonatomic, strong) NSNumber *resultsPricePerPoint; 

@end 

有了这样的实现:

#import "userResults.h" 

@implementation userResults 

@end 

我将建立的这种多值一个NSMutableArray称为结果。

我希望能够在* resultsSaving字段中对结果中的记录进行排序。

我已经填充了两个数组results1和results2,并将它们卡在较大的数组中,然后尝试使用此代码进行排序。

results = [NSMutableArray arrayWithObjects:results1,results2,nil]; 
NSSortDescriptor *sort = [NSSortDescriptor sortDescriptorWithKey:@"resultsSaving" ascending:YES]; 
[results sortUsingDescriptors:sort]; 

不起作用。我认为我可能有一些概念问题。任何帮助将不胜感激。

布莱恩

回答

0

互联网的多冲刷后,我发现这个答案:

NSSortDescriptor *sortDescriptor; 
sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"resultsSaving" 
              ascending:NO]; 
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 
sortedArray = [results sortedArrayUsingDescriptors:sortDescriptors]; 

奇怪的是,你不能做的下降,但必须给出一个上升:NO。这很奇怪。