iphone之NSArray比较大小

长平狐 发布于 2013/12/25 17:17
阅读 125
收藏 0
 //排序
                    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🇲🇲ss"];
                        
                        NSDate *date1 = [formatter dateFromString:newCenter1.newtime];
                        NSDate *date2 = [formatter dateFromString:newCenter2.newtime];
                        
                        int i = [date1 compare:date2];
                        
                        return -i;
                    }];


NewCenter是自定义的类





原文链接:http://blog.csdn.net/rhljiayou/article/details/9147917
加载中
返回顶部
顶部