的一個NSArray我的NSDictionary unsortedArray的一個NSArray樣子:排序的NSDictionary
(
{symbol = "ABC"; price = "9.01";}
{symbol = "XYZ"; price = "3.45";}
...
(
這裏是排序代碼:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"price" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor];
NSArray *sortArray = [unsortedArray sortedArrayUsingDescriptors:sortedDescriptors];
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:@"symbol" ascending:YES];
NSArray *sortDescriptors = [NSArray arrayWithObject:descriptor];
NSArray *sortArray = [unsortedArray sortedArrayUsingDescriptors:sortedDescriptors];
的符號鍵排序結果是好的,但價格的關鍵沒有排序。什麼可能是錯的?價格是在NSString,但想排序它看起來像
3.45
9.01
...
在此先感謝。
這似乎不是你的實際代碼:你使用變量名'sortedDescriptors',它在上面代碼中沒有定義。請發佈您的實際代碼。 – Monolo
「什麼可能是錯的?」那麼,*做錯了什麼?畢竟,這兩種價格是正確分類的。 –