2012-03-06 69 views
0

我想排序數組NSString的的:NSArray的排序:

"Page_1", 
"Page_10", 
"Page_11", 
"Page_12", 
"Page_13", 
"Page_14", 
"Page_15", 
"Page_16", 
"Page_17", 
"Page_18", 
"Page_19", 
"Page_2", 
"Page_20", 
"Page_21", 
"Page_22", 
"Page_23", 
"Page_24", 
"Page_3", 
"Page_4", 
"Page_5", 
"Page_6", 
"Page_7", 
"Page_8", 
"Page_9" 

,但我不斷收到一個錯誤與此代碼:

NSArray* sortedArray = [currentViews sortedArrayUsingSelector:@selector(compare:NSNumericSearch)]; 

甚至不知道這是採取正確的處理方法,看着NSArray文檔讓我覺得我應該用比較器。任何幫助,將不勝感激。

回答

2

你確實需要一個比較器,因爲你想要排序的實際上是一個NSString,而不是一個NSNumber。

-1

您無法修復@selector中的參數 - @selector(compare:NSNumericSearch)正在尋找一種方法compare:NSNumericSearch而且不存在!

您可以使用一個比較器來調用正確的方法進行比較:

NSArray *sortedArray = [currentViews sortedArrayUsingComparator:(NSComparator)^(NSString *a, NSString *b) 
         { 
          return [a compare:b options:NSNumericSearch]; 
         } 
         ];