zoukankan      html  css  js  c++  java
  • 首個字母排序

    NSString *pathList = [[NSBundle mainBundle] pathForResource:@"models" ofType:@"json"]; 

        NSString *sourceList = [NSString stringWithContentsOfFile:pathList encoding:NSUTF8StringEncoding error:nil];

        NSDictionary *resultList = [sourceList objectFromJSONString];

        //以系名的首個字目為分組名,重新生成可變數組

        NSMutableDictionary *aIndexDictionary = [[NSMutableDictionary alloc] init];

        NSMutableArray *currentArray;

        NSRange aRange = NSMakeRange(0, 1);

        NSString *firstLetter;    

        NSArray *tempList = [resultList objectForKey:@"data"];

        //以系名的首個字目為 key

        NSMutableArray *keys=[[NSMutableArray alloc]init];    

        //遍歷數組

        for (int i=0; i<[tempList count]; i++) {

            //獲得首字母

            firstLetter = [[[tempList objectAtIndex:i] objectForKey:@"model"] substringWithRange:aRange];

            

            if ([aIndexDictionary objectForKey:firstLetter] == nil) {

                currentArray = [NSMutableArray array];

                [aIndexDictionary setObject:currentArray forKey:firstLetter];

                

                [keys addObject:firstLetter];

            }

            //添加字典

            [currentArray addObject:[tempList objectAtIndex:i]];

            

        }

        

        self.modelDictionary = aIndexDictionary;

        //NSLog(@"%@",aIndexDictionary);

        self.modelsList = keys;

  • 相关阅读:
    Razor 视图引擎的一些属性和方法
    Asp.Net Mvc Razor
    微信小程序时代已经来临
    ionic常用命令记录
    ionic中将service中异步返回的数据赋值给controller的$scope
    nodejs连接mysql实例
    转载:ionic+nodejs开发遇到的跨域和post请求数据问题
    NodeJs-- 新建项目实例
    Bootstrap学习指南
    ios开发环境配置及cordova安装与常用命令
  • 原文地址:https://www.cnblogs.com/careerman/p/2645335.html
Copyright © 2011-2022 走看看