2011-06-01 48 views
0

在對數組進行排序時,我得到:1,10,2,3,4,5,6,7,8,9。什麼地方出了錯 ?分類列表數組問題

我的代碼是:

 NSArray *sortedArray = [optionKeys sortedArrayUsingSelector:@selector(localizedCaseInsensitiveCompare:)]; 

其中optionKeys是:7,3,8,4,9,5,1,6,2,10

我還曾試圖CaseInsensitiveCompare:並獲得相同的結果。

+0

可能的重複[如何讓sortedArrayUsingSelector使用整數來排序而不是String?](http://stackoverflow.com/questions/2752992/how-to-let-the-sortedarrayusingselector-using-integer-to-排序INSTEAD-OF-字符串) – 2011-06-01 16:01:43

回答

0

您正在執行字符串排序而不是數字排序。見this answer

0

看看這個answer。你想要做一個數字排序而不是一個字符串排序。