zoukankan      html  css  js  c++  java
  • 联系人按照A~~~Z排列

        // 01 创建可变字典,存储每一个key对应的数据列表
        
        NSMutableDictionary *nationWithCodeDicList = [NSMutableDictionary dictionary];
        
        // 02 遍历数组_dataList中的小字典
        
        NSString *path = [[NSBundle mainBundle] pathForResource:@"nationcodenumber" ofType:@"plist"];
        NSArray *_dataList = [NSArray arrayWithContentsOfFile:path];
        for (NSDictionary *nationWithCodeDic in _dataList) {
            
            // 03 得到国家名称
    //        Model *model =[[Model alloc]init];
            NSString *nationName = nationWithCodeDic[@"Name"];
            
            // 04 转成可变字符串
            
            NSMutableString *mutableNationName = [NSMutableString stringWithString:nationName];
            
            // 05 先转换为带声调的拼音
            
            CFStringTransform((CFMutableStringRef)mutableNationName,NULL, kCFStringTransformMandarinLatin,NO);
            
            // 06 再转换为不带声调的拼音
            
            CFStringTransform((CFMutableStringRef)mutableNationName,NULL, kCFStringTransformStripDiacritics,NO);
            
            // 07 得到首字母之大写形式并设置为字典的一个key
            
            NSString *key = [mutableNationName substringToIndex:1].uppercaseString;
            NSLog(@"%@",key);
            // 08 获取nationWithCodeDicList中key对应的value(存放若干国家小字典的数组,国家名字的首字母都是key)nationWithCodeListKey
            
            NSMutableArray *nationWithCodeListKey = [nationWithCodeDicList objectForKey:key];
            
            // 09 若此数组为空,则创建并保存到字典对应的key
            
            if (nationWithCodeListKey == nil) {
                
                nationWithCodeListKey = [NSMutableArray array];
                
                [nationWithCodeDicList setObject:nationWithCodeListKey forKey:key];
                
            }
            //MKMKMKMKMKMKMKMKMK
            Model *model =[Model currentModelWithDict:nationWithCodeDic];
            // 10 若有此数组,就把本次遍历得到的数据(_dataList中的小字典)加入其中
            [nationWithCodeListKey addObject:model];
    //        [nationWithCodeListKey addObject:nationWithCodeDic];
            // 11 获取当前好友列表中所有的组标题 使用compare得到有顺序的字母数组
            
            self.shouzimuarray = [[nationWithCodeDicList allKeys] sortedArrayUsingSelector:@selector(compare:)];
        }
        self.dictionart = nationWithCodeDicList;
  • 相关阅读:
    db2缓冲池调优
    linux下安装rpm出现error: Failed dependencies
    linux下挂载磁盘
    db2 常见错误以及解决方案[ErrorCode SQLState]
    db2数据库表操作错误SQL0668N Operation not allowed for reason code "1" on table "表". SQLSTATE=57016的解决方法
    db2用户权限赋值
    db2查看当前用户模式及当前用户的权限
    loadrunner常用函数整理
    书上的脚本案例
    hdu 1711---KMP
  • 原文地址:https://www.cnblogs.com/mkai/p/6229462.html
Copyright © 2011-2022 走看看