我有一个对象,如下
#import <Foundation/Foundation.h>
@interface CountriesDAO : NSObject
@property (nonatomic, retain) NSString * countryname;
@end
#import "CountriesDAO.h"
@implementation CountriesDAO
@synthesize countryname;
@end
我已将它保存在 appDelegate 内的数组中。
@property (nonatomic, retain) NSArray *countriesArray;
@synthesize countriesArray;
在另一个 Controller 中,我像获取它一样
NSArray *countriesArray = appDelegate.countriesArray; It works fine and I get array.
当我尝试以这种方式对其进行排序时。
NSArray *countriesArray1 = appDelegate.countriesArray;
NSSortDescriptor *valueDescriptor = [[NSSortDescriptor alloc] initWithKey"countryname" ascending:YES];
NSArray * descriptors = [NSArray arrayWithObject:valueDescriptor];
countriesArray = [countriesArray1 sortedArrayUsingDescriptors:descriptors];
我得到错误
[__NSCFType count]: unrecognized selector sent to instance 0xa83b4d0
2013-11-01 13:21:08.882 ECP[13597:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType count]: unrecognized selector sent to instance 0xa83b4d0'
这里国家数组定义为
@property (nonatomic, retain) NSArray *countriesArray;
Best Answer-推荐答案 strong>
我是这样做的,它对我有用。
countriesArray = [[NSMutableArray alloc] init];
for (CountriesDAO *info in appDelegate.countriesArray) {
[countriesArray addObject:info.countryname];
}
[countriesArray sortUsingSelectorselector(localizedCaseInsensitiveCompare];
关于ios - 在 NSArray 中排序对象?,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/19723218/
|