可能重複:
How to sort an NSMutableArray with custom objects in it?排序一個的NSMutableArray由對象值
我在這裏排序的NSMutableArray newsDataArray含有NewsData對象與整型屬性NewSID的。現在正在工作。但我怎麼能以更好的方式做到這一點。有沒有更好的方法...
NSSortDescriptor *sortDesc = [[NSSortDescriptor alloc] initWithKey:@"newsID" ascending:NO];
NSArray *tempArray = [newsDataArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortDesc]];
NSMutableArray *sortedArray = [NSMutableArray arrayWithArray:tempArray];
NSLog(@"sortedArray=%@" ,sortedArray);
當我使用下面的方法阻止一些錯誤顯示。我想排序newsDataArray作爲我最後的結果....誰能給我一個明顯的例子...
檢查這個問題的答案,它提供了幾種方法來做到這一點:http://stackoverflow.com/questions/805547/how-to-sort-an-nsmutablearray-with-custom-objects-in-it –