最关键的代码是:
-(void)startArraySort:(NSString *)keystring isAscending:(BOOL)isAscending
{
//self.destinationArry=[[NSMutableArray alloc]init];
NSSortDescriptor* sortByA = [NSSortDescriptor sortDescriptorWithKey:keystring ascending:isAscending];
//destinationArry 排序后的数组 sourceArry 源数据
self.destinationArry=[[NSMutableArray alloc]initWithArray:[self.sourceArry sortedArrayUsingDescriptors:[NSArray arrayWithObject:sortByA]]];
for (BookItem *testbook in self.destinationArry) {
NSLog(@"%@,%@,%@,%@",testbook.bookName,testbook.bookFileName,testbook.bookDescription,testbook.modifyTime);
}
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.sourceArry =[[NSMutableArray alloc]init];
[self reset];
[self startArraySort:@"bookName" isAscending:YES];