IOS 数组的简单排序

数组大致是里面都是对象,然后根据对象里面的一个字段日期进行排序,然后根据日期大大小显示在tableview上

网上找到代码

数组形式 arry=[{NAME:xxx,APPLY_DATE:20121211},{NAME:xxx,APPLY_DATE:20090815},{NAME:xxx,APPLY_DATE:20111211}];

NSComparisonResult compare(NSDictionary *firstDict, NSDictionary *secondDict, void *context){ 
    if ([firstDict objectForKey:@"APPLY_DATE"] integerValue]< [secondDict objectForKey:@"APPLY_DATE"] integerValue])
        return NSOrderedAscending;
    else if ([firstDict objectForKey:@"APPLY_DATE"] integerValue] >[secondDict objectForKey:@"APPLY_DATE"]integerValue])
        return NSOrderedDescending;
    else
        return NSOrderedSame;
}
然后就调用上面的方法就可以排出来的,然后要实现查询除数据,显示在tablivew上面,发现有许多的重复的数据,最后查到的原因是

 NSString *CellIdentifier = [NSString stringWithFormat:@"queryCellId%d%d", indexPath.section, indexPath.row];
//以前是这样的 NSString *CellIdentifier = @"asdasdasdad";   <br> UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
发现需要加上他们的indexpath.row,indexpath.section这样查询出来的数据显示在tablivew上才不会重复,而且每次查询的时候又发现有时数据的不会根据查询的变换,最后知道是要把数组 每次查询前  [claimList removeAllObjects];移除后这样才能每次查询都是最新的,总结下

原文地址:https://www.cnblogs.com/zhangsongbai/p/3102607.html