iphone之NSArray比较大小

 //排序
                    NSArray *tempArray = [[NSArray alloc]initWithArray:self.contentArray];
                    
                    tempArray = [tempArray sortedArrayUsingComparator:^NSComparisonResult(NewCenter *newCenter1, NewCenter *newCenter2) {
                        
                        NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                        [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
                        
                        NSDate *date1 = [formatter dateFromString:newCenter1.newtime];
                        NSDate *date2 = [formatter dateFromString:newCenter2.newtime];
                        
                        int i = [date1 compare:date2];
                        
                        return -i;
                    }];


NewCenter是自定义的类




 

posted @ 2013-06-22 12:37  jlins  阅读(237)  评论(0编辑  收藏  举报