//order by price or time
-(void)sortFilght:(id)sender
{
UIButton *btn = (UIButton *)sender;
NSArray *arr = [self.fListArray sortedArrayUsingComparator:^NSComparisonResult(id item1, id item2) {
HFFlight *flight1 = item1;
HFFlight *flight2 = item2;
HFCabin *cabin1 = [flight1.cabins objectAtIndex:0];
HFCabin *cabin2 = [flight2.cabins objectAtIndex:0];
if (btn.tag == 1) {//价格排序
if (cabin1.adultPrice > cabin2.adultPrice) {
returnNSOrderedDescending;
} else if (cabin1.adultPrice < cabin2.adultPrice) {
return NSOrderedAscending;
} else {
return NSOrderedSame;
}
}else{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
dateFormatter.dateFormat = @"yyyy-MM-dd HH:mm";
NSDate *date1 = [dateFormatter dateFromString:flight1.orgDateTime1];
NSDate *date2 = [dateFormatter dateFromString:flight2.orgDateTime1];
NSComparisonResult result = [date1 compare:date2];
return result;
}
}];
NSMutableArray *mutableArray = [[NSMutableArray alloc] initWithArray:arr];
self.fListArray = mutableArray;
[self.expansionTableViewreloadData];
}