【发布时间】:2012-01-17 12:50:30
【问题描述】:
可能重复:
How to sort an NSMutableArray with custom objects in it?
我在这里对包含 NewsData 对象的 NSMutableArray newsDataArray 进行排序,该对象具有 int 属性 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 作为我的最终结果....任何人都给我一个明确的例子...
【问题讨论】:
-
检查这个问题的答案,它提供了几种方法:stackoverflow.com/questions/805547/…
标签: objective-c ios cocoa-touch