zoukankan      html  css  js  c++  java
  • [ios]NSArray中的数据进行排序 sortedArrayUsingDescriptors

    //组装数据
    array=[[NSMutableArray alloc] initWithCapacity:11];

    NSMutableDictionary *dir6=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir6 setObject:@"曹磊" forKey:@"FriendName"];
    [dir6 setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir6];
    [dir6 release];


    NSMutableDictionary *dir=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir setObject:@"王军" forKey:@"FriendName"];
    [dir setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir];
    [dir release];

    NSMutableDictionary *dir1=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir1 setObject:@"111" forKey:@"FriendName"];
    [dir1 setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir1];
    [dir1 release];

    NSMutableDictionary *dir2=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir2 setObject:@"王兴朝" forKey:@"FriendName"];
    [dir2 setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir2];
    [dir2 release];

    NSMutableDictionary *dir3=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir3 setObject:@"wangjun" forKey:@"FriendName"];
    [dir3 setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir3];
    [dir3 release];

    NSMutableDictionary *dir4=[[NSMutableDictionary alloc] initWithCapacity:1];
    [dir4 setObject:@"apk" forKey:@"FriendName"];
    [dir4 setObject:@"曹磊" forKey:@"FriendID"];
    [array addObject:dir4];
    [dir4 release];


    self.myArray=array;
    [array release];
    NSLog(@">>>>>>排序前>>>>>>>>");
    for (int i=0; i<[self.myArray count]; i++) {
    NSLog(@"%@",[[self.myArray objectAtIndex:i] objectForKey:@"FriendName"]);
    }

    NSSortDescriptor *sorter = [[NSSortDescriptor alloc] initWithKey:@"FriendName" ascending:YES];
    NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:&sorter count:1];
    NSArray *sortedArray = [self.myArray sortedArrayUsingDescriptors:sortDescriptors];


    [sorter release];

    NSLog(@"\n\n\n\n\n>>>>>>排序后>>>>>>>>");
    for (int i=0; i<[sortedArray count]; i++) {
    NSLog(@"%@",[[sortedArray objectAtIndex:i] objectForKey:@"FriendName"]);
    }

    http://wangjun.easymorse.com/?p=1294

  • 相关阅读:
    【转】跨域的理解与实现
    【3.5】从今天开始学习WCF技术
    LAB.js使用
    资源文件的动态加载
    C#对图片文件的压缩、裁剪操作初探
    WCF技术剖析_学习笔记之一
    SQL 写入调优
    【转】Nosql,为什么要使用
    wcf配置文件
    wcf错误
  • 原文地址:https://www.cnblogs.com/jinjiantong/p/3023301.html
Copyright © 2011-2022 走看看