2011-02-28 64 views
0

我有钥匙的NSArrayNSDictionary这样的:如何排序键的NSArray?

NSArray *array = [[NSArray alloc] initWithArray:[myDict allKeys]]; 
[array sortedArrayUsingSelector:@selector(compare:)]; 

为什么不阵列得到命令?

回答

3

我认为它有用,你

NSDictionary *stateZip; 
NSArray *states; 
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:plistPath];   
self.stateZip=dictionary; 
[dictionary release]; 


NSArray *component = [self.stateZip allKeys]; 
NSArray *sorted =[component sortedArrayUsingSelector:@selector(compare:)]; 
self.states=sorted; 

ragards, CNSivakUmar

+0

完美!我是个假人! – 2011-02-28 13:01:05

+0

没有人...每个人都有同样的 - 平等..不要这样说.. – CNSivakumar 2011-02-28 13:39:04

0

Heyy试试这个....

NSSortDescriptor *lastNameSorter = [[NSSortDescriptor alloc] initWithKey:@"lastName" ascending:YES]; 

这样做,我把这个在data.h/M文件作为NSMutableArray里与数据或viewcontroller.h/M档为我创建需要在表格中显示数据?

0

这可能会有所帮助:

NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@”self” ascending:YES]; 
[array sortUsingDescriptors:[NSArray arrayWithObject:sortDesc]]; 
[sortDesc release]; 

欲了解更多信息,看看

  1. NSSortDescriptor
  2. 排序,NSArrays
+0

不工作... [__NSArrayI sortUsingDescriptors:]:无法识别的选择发送到实例0x6a58bc0 – 2011-02-28 12:55:11