美文网首页iosiOS_UIKit
UILocalizedIndexedCollation排序

UILocalizedIndexedCollation排序

作者: 絮语时光杨 | 来源:发表于2018-05-14 11:57 被阅读0次

1、获取单例的collation
UILocalizedIndexedCollation *collation = [UILocalizedIndexedCollation currentCollation];

//标题数组
NSInteger sectionTitlesCount = [[collation sectionTitles] count];
//设置sections数组初始化:元素包含userObjs数据的空数据
NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
for (NSInteger index = 0; index < sectionTitlesCount; index++) {
    NSMutableArray *array = [[NSMutableArray alloc] init];
    [newSectionsArray addObject:array];
}

2、分类 - 将用户数据进行分类,存储到对应的sesion数组中
for (MTDUserBaseModel *p in self.friendListRequest.friendMutableArray) {
    NSInteger sectionNumber = [collation sectionForObject:p collationStringSelector:@selector(userNickname)];
    NSMutableArray *sectionNames = newSectionsArray[sectionNumber];
    [sectionNames addObject:p];

}

3、排序 - 对每个已经分类的数组中的数据进行排序
for (NSInteger index = 0; index < sectionTitlesCount; index++) {
     NSMutableArray *personArrayForSection = newSectionsArray[index];
     NSArray *sortedPersonArrayForSection = [collation sortedArrayFromArray:personArrayForSection collationStringSelector:@selector(userNickname)];
    newSectionsArray[index] = sortedPersonArrayForSection;
}

相关文章

网友评论

    本文标题:UILocalizedIndexedCollation排序

    本文链接:https://www.haomeiwen.com/subject/vlvddftx.html