2015-04-06 114 views
0

我有一个NSMutableArraymainArray,在这个mainArray的每一个索引I具有长度为2,3或4。如何根据主阵列内长度数组进行排序

我想以这样的方式来排序mainArray的其它阵列那阵列里面有更大的长度在mainArray之上。

回答

3

看一看this question,这可能帮助

NSSortDescriptor *sd = [NSSortDescriptor sortDescriptorWithKey:@"@count" 
               ascending:NO]; 
NSArray *sds = [NSArray arrayWithObject:sd]; 
NSArray *sortedArray = [array sortedArrayUsingDescriptors:sds]; 

它会以这样的方式,具有较高计数内阵列将在上面进行排序mainArray

+0

都能跟得上你的代码不排序:( – 2015-04-06 07:08:27

+0

你传递'mainArray'到位代码array'的'? – 2015-04-06 07:27:15

+0

是的,我通过我的主阵列到位数组。 – 2015-04-06 07:32:22

0

这个怎么样?

NSSortDescriptor *sortDescriptor; 
sortDescriptor = [[[NSSortDescriptor alloc] initWithKey:[subArray count] 
               ascending:NO] autorelease]; 
NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; 

[myArray sortUsingDescriptors:sortDescriptors]; 

subArrayinside array

[subArray count]会做的伎俩。

+0

但我没有一个子数组,我有几个子数组,它会采用哪个子数数 – 2015-04-06 07:02:26

+0

@SJ:你可以发布样本json数据吗? – 2015-04-06 07:12:00

+0

我没有json数据。它像mianArray [0] = {a,b} ... mianArray [1] = {x,y,z} ... – 2015-04-06 07:24:16

相关问题