Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iOS 9中按字母顺序对字典数组排序_Ios_Objective C_Iphone_Nsmutablearray_Nsdictionary - Fatal编程技术网

如何在iOS 9中按字母顺序对字典数组排序

如何在iOS 9中按字母顺序对字典数组排序,ios,objective-c,iphone,nsmutablearray,nsdictionary,Ios,Objective C,Iphone,Nsmutablearray,Nsdictionary,我正在获取字典数组,我想按字母顺序对数据进行排序以显示索引tableview功能。如何使用字典对数组进行排序以实现索引tableview。要对数组进行排序,我的代码如下: NSArray *array1 = [NSArray arrayWithArray:resultArray]; NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"first_name" ascending:YES selector:

我正在获取字典数组,我想按字母顺序对数据进行排序以显示索引tableview功能。如何使用字典对数组进行排序以实现索引tableview。要对数组进行排序,我的代码如下:

NSArray *array1 = [NSArray arrayWithArray:resultArray];
NSSortDescriptor *sortByName = [NSSortDescriptor sortDescriptorWithKey:@"first_name" ascending:YES selector:@selector(caseSensitive)] ;
NSArray *sortDescriptors = [NSArray arrayWithObject:sortByName];
sortedArray = [array1 sortedArrayUsingDescriptors:sortDescriptors];
我正在尝试使用代码,但当我在tableview中显示数据时,它变得不匹配。请建议我正确的方法。谢谢。

请使用此代码:

NSArray *array1 = [NSArray arrayWithArray:resultArray];
NSSortDescriptor* sortOrder = [NSSortDescriptor sortDescriptorWithKey: @"self" ascending: YES];
array1 = [array1 sortedArrayUsingDescriptors: [NSArray arrayWithObject: sortOrder]];
试试这个

 NSArray *arr = @[@{@"first_name":@"B"},@{@"first_name":@"A"}];
 NSSortDescriptor *desc = [NSSortDescriptor sortDescriptorWithKey:@"first_name" ascending:YES];
arr =  [arr sortedArrayUsingDescriptors:@[desc]];

我们用下面的方法得到了解

[self.jsonData sortUsingDescriptors: [NSArray arrayWithObjects: [NSSortDescriptor sortDescriptorWithKey:"fullname" ascending:YES], [NSSortDescriptor sortDescriptorWithKey:"id" ascending:NO], nil]];
其中:-

jsonData—保存已解析JSON数据的可变数组

fullname—我们要排序的数据

id-内部字典附带的唯一数据

参考:

试试这个


让sortedKeys=(self.dictBrands.allKeys as![String]).sort(您是否尝试了下面发布的答案,并得到了任何解决方案?它与iOS8、iOS7、6、5等中的情况基本相同。。。