可能重复:
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 –