2011-02-28 59 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