iOS仿微信联系人界面中联系人按姓名首字母分类UILocalizedIndexedCollation
来源:互联网 发布:初中物理知识网络 编辑:程序博客网 时间:2024/04/30 03:45
字母分组排序神器:UILocalizedIndexedCollation
- (void)configureTableViewSection { // 实例化 UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation]; // [collation sectionTitles]得到一个包含(A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z,#)的数组 // numberOfSections为27 NSUInteger numberOfSections = [[collation sectionTitles] count]; // 初始化一个sectionMutableArray来存放数据,其27个元素都是NSMutableArray NSMutableArray *sectionMutableArray = [[NSMutableArray alloc] init]; for (NSUInteger index = 0; index < numberOfSections; index ++) { [sectionMutableArray addObject:[[NSMutableArray alloc] init]]; } /* * 假设现在有个一个数据模型DataModel类,DataModel类里面有字段nameStr、avatarStr,生成若干DataModel的实例已经加入到了数组(NSMutableArray)dataMutableArray中 */ for (DataModel *oneDataModel in dataMutableArray) { // 获取nameStr首字母所在的位置 NSUInteger sectionIndex = [collation sectionForObject:oneDataModel collationStringSelector:@selector(nameStr)]; [sectionMutableArray[sectionIndex] addObject:oneDataModel]; } // 对分成一类的数组进行排序 for (NSUInteger index = 0; index < numberOfSections; index ++) { // 获取某一字母分类中得数组 NSMutableArray *indexSectionMutableArray = sectionMutableArray[index]; // 以nameStr字段排序 NSArray *sortedSectionArray = [collation sortedArrayFromArray:indexSectionMutableArray collationStringSelector:@selector(nameStr)]; sectionMutableArray[index] = sortedSectionArray; } NSMutableArray *emptyMutableArray = [NSMutableArray new]; NSMutableArray *sectionTitleMutableArray = [NSMutableArray new]; [sectionMutableArray enumerateObjectsUsingBlock:^(NSArray *arrary, NSUInteger idx, BOOL *stop) { if (arrary.count == 0) { // 可能有很多arrary.count为0的,把这些arrary加到emptyMutableArray里,然后从sectionMutableArray里移除 [emptyMutableArray addObject:arrary]; } else { // section标题,如A,B,C... [sectionTitleMutableArray addObject:[collation sectionTitles][idx]]; } }]; [sectionMutableArray removeObjectsInArray:emptyMutableArray]; NSMutableArray *showMutableArray = [[NSMutableArray alloc] init]; // 自己加图片 NSArray *dictArray = @[@{@"nameStr": @"新的朋友", @"imageNameStr": @""}, @{@"nameStr": @"群聊", @"imageNameStr": @""}, @{@"nameStr": @"标签", @"imageNameStr": @""}, @{@"nameStr": @"公众号", @"imageNameStr": @""}]; for (NSDictionary *oneDict in dictArray) { /* * 假设现在有个一个数据模型ShowModel类,ShowModel类里面有字段nameStr、imageNameStr */ ShowModel *showModel = [ShowModel new]; showModel.nameStr = oneDict[@"nameStr"]; showModel.imageNameStr = oneDict[@"imageNameStr"]; [showMutableArray addObject:showModel]; } // 第一个section显示自定义的 [sectionMutableArray insertObject:showMutableArray atIndex:0]; // sectionTitleMutableArray存放的是section的标题A,B,C...,第一个section不需要section title [sectionTitleMutableArray insertObject:@"" atIndex:0]; // 把sectionMutableArray、sectionTitleMutableArray全局化,作为tableView的数据源 self.sectionMutableArray = sectionMutableArray; self.sectionTitleMutableArray = sectionTitleMutableArray;}
0 0
- iOS仿微信联系人界面中联系人按姓名首字母分类UILocalizedIndexedCollation
- android仿微信联系人 首字母分类
- android仿微信联系人 首字母分类(旧)
- (二)Android仿微信—仿微信联系人 首字母分类
- Android仿微信(二)——仿微信联系人 首字母分类
- 如何在泰国#组联系人列表中的联系人姓名分类?
- iOS中获取本地通讯录联系人以及汉字首字母排序
- android 联系人 首字母分类 封装(更新)
- UILocalizedIndexedCollation ios首字母排列
- iOS实现联系人按照首字母进行排序
- Android中 根据电话号码获取联系人姓名
- 根据电话号码查找通讯录中联系人姓名
- 手机中预置联系人(姓名,号码,头像)
- Android中根据电话号码取联系人姓名
- 通讯录联系人姓名排序
- 联系人查询---姓名、手机号
- android 仿微信联系人 首字母分组快速索引
- IOS调用系统联系人界面获取联系人信息
- oracle 递归查询
- 1005. Spell It Right (20)
- Mongodb学习(1)安装以及配置
- cocos js 代码阅读笔记_170510(一)
- Hiberate二级缓存
- iOS仿微信联系人界面中联系人按姓名首字母分类UILocalizedIndexedCollation
- 线程安全的SharedpreferenceUtil
- 【其他] Unity 几种优化建议】
- 设计模式之原型模式
- Mybatis步骤
- 四种线程池
- 理解JSON对象
- Java多线程(2)
- Java图片缩略图裁剪水印缩放旋转压缩转格式-Thumbnailator图像处理