我正在尝试在 iPhone 应用程序中按 Aa-Zz 格式对 NSMutablArray 值进行排序。我在我的项目中使用了以下代码。
for (id key in [dictionary allKeys])
{
id value = [dictionary valueForKey:key];
[duplicateArray addObject:value];
[value release];
value =nil;
NSSortDescriptor *sortdis = [[[NSSortDescriptor alloc] initWithKey:@"Name" ascending:YES] autorelease];
NSArray *discriptor = [NSArray arrayWithObjects:sortdis,nil];
mutableArray = [[duplicateArray sortedArrayUsingDescriptors:discriptor]retain];
}
NSLog(@"mutableArray : %@", mutableArray);
[mutableArray sortUsingSelector:@selector(caseInsensitiveCompare:)];
应用程序因此错误日志而崩溃:[__NSArrayI sortUsingSelector:]: unrecognized selector sent to instance.
但是,我已经搜索并找到了崩溃的原因。我的 mutableArray 值是这样的,
(
{
Id = 00001;
Name = "ABCD";
},
{
Id = 00002;
Name = "BCDE";
},
{
Id = 00003;
Name = "ZXYS";
},
{
Id = 00004;
Name = "abcd";
},
{
Id = 00009;
Name = "bcde";
},
)
我想对这个数组值进行排序,如ABCD、abcd、BCDE、bcde、ZXYs。任何人都可以帮助解决这个问题。