zoukankan      html  css  js  c++  java
  • 一段排序代码,

    //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];

    }

  • 相关阅读:
    File IO (Examples)
    File IO (AsciiToBinary / BinaryToAscii)
    Bit Operation (Message Compression/Decompression)
    Use GDB to debug code (2Example)
    Linked List in C (3Sorted List)
    在用户控件 ASCX 创建用户控件 ASCX
    恢复现有mongodb中的单个集合
    恢复现有mongodb中的单个集合
    WebForm与MVC混用
    WebForm与MVC混用
  • 原文地址:https://www.cnblogs.com/guligei/p/3030930.html
Copyright © 2011-2022 走看看