码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 数组排序(原创)

时间:2015-02-12 12:27:31      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:

    NSArray *sortedArray = [userArr sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2)
                            {
                                if([VShowUtil isEmptyString:[obj1 objectForKey:@"vlevel"]])
                                {
                                    return NSOrderedDescending;
                                }
                                if([VShowUtil isEmptyString:[obj2 objectForKey:@"vlevel"]])
                                {
                                    return NSOrderedSame;
                                }
                                if ([[obj1 objectForKey:@"vlevel"] intValue] > [[obj2 objectForKey:@"vlevel"] intValue]){
                                    
                                    return NSOrderedSame;
                                }
                                if ([[obj1 objectForKey:@"vlevel"] intValue] < [[obj2 objectForKey:@"vlevel"] intValue]){
                                    return NSOrderedDescending;
                                }
                                return NSOrderedSame;
                            }];
    [userArr removeAllObjects];
    [userArr addObjectsFromArray:sortedArray];

 

 

 

 

 

 

/*!
 *  @Author Yunis_song, 14-12-22 15:12:38
 *
 *  @brief  对付费道具进行价格排序
 *
 *  @param userArr 付费道具数组
 */
- (void)shortArr:(NSMutableArray *)userArr
{
    NSArray *sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"price" ascending:YES]];
    [userArr sortUsingDescriptors:sortDescriptors];

}

 

iOS 数组排序(原创)

标签:

原文地址:http://www.cnblogs.com/yunis/p/4287550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!