你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
搜索问题、话题或人...
输入关键字进行搜索
搜索:
问题
精选文章
开源项目
视频教程
活动
· · ·
帮助
登录
注册
环信_iOS
iosdemo好友列表索引
demo有这个方法,要实现他么
没有找到相关结果
已邀请:
与内容相关的链接
提交
2 个回复
不轻易言弃
是这个方法
- (NSMutableArray *)sortDataArray:(NSArray *)dataArray
{
//建立索引的核心
UILocalizedIndexedCollation *indexCollation = [UILocalizedIndexedCollation currentCollation];
[self.sectionTitles removeAllObjects];
[self.sectionTitles addObjectsFromArray:[indexCollation sectionTitles]];
//返回27,是a-z和#
NSInteger highSection = [self.sectionTitles count];
//tableView 会被分成27个section
NSMutableArray *sortedArray = [NSMutableArray arrayWithCapacity:highSection];
for (int i = 0; i <= highSection; i++) {
NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:1];
[sortedArray addObject:sectionArray];
}
//名字分section
for (EMBuddy *buddy in dataArray) {
//getUserName是实现中文拼音检索的核心,见NameIndex类
NSString *firstLetter = [ChineseToPinyin pinyinFromChineseString:buddy.username];
NSInteger section = [indexCollation sectionForObject:[firstLetter substringToIndex:1] collationStringSelector:@selector(uppercaseString)];
NSMutableArray *array = [sortedArray objectAtIndex:section];
[array addObject:buddy];
}
//每个section内的数组排序
for (int i = 0; i < [sortedArray count]; i++) {
NSArray *array = [[sortedArray objectAtIndex:i] sortedArrayUsingComparator:^NSComparisonResult(EMBuddy *obj1, EMBuddy *obj2) {
NSString *firstLetter1 = [ChineseToPinyin pinyinFromChineseString:obj1.username];
firstLetter1 = [[firstLetter1 substringToIndex:1] uppercaseString];
NSString *firstLetter2 = [ChineseToPinyin pinyinFromChineseString:obj2.username];
firstLetter2 = [[firstLetter2 substringToIndex:1] uppercaseString];
return [firstLetter1 caseInsensitiveCompare:firstLetter2];
}];
[sortedArray replaceObjectAtIndex:i withObject:[NSMutableArray arrayWithArray:array]];
}
NSLog(@"ssssssssss===%@",sortedArray);
return sortedArray;
}
Half12345
看你的需求啊,有需要就实现啊。
要回复问题请先
登录
或
注册
发起人
不轻易言弃
问题状态
最新活动:
2015-09-06 19:46
浏览:
4558
关注:
2
人
2 个回复
不轻易言弃
- (NSMutableArray *)sortDataArray:(NSArray *)dataArray
{
//建立索引的核心
UILocalizedIndexedCollation *indexCollation = [UILocalizedIndexedCollation currentCollation];
[self.sectionTitles removeAllObjects];
[self.sectionTitles addObjectsFromArray:[indexCollation sectionTitles]];
//返回27,是a-z和#
NSInteger highSection = [self.sectionTitles count];
//tableView 会被分成27个section
NSMutableArray *sortedArray = [NSMutableArray arrayWithCapacity:highSection];
for (int i = 0; i <= highSection; i++) {
NSMutableArray *sectionArray = [NSMutableArray arrayWithCapacity:1];
[sortedArray addObject:sectionArray];
}
//名字分section
for (EMBuddy *buddy in dataArray) {
//getUserName是实现中文拼音检索的核心,见NameIndex类
NSString *firstLetter = [ChineseToPinyin pinyinFromChineseString:buddy.username];
NSInteger section = [indexCollation sectionForObject:[firstLetter substringToIndex:1] collationStringSelector:@selector(uppercaseString)];
NSMutableArray *array = [sortedArray objectAtIndex:section];
[array addObject:buddy];
}
//每个section内的数组排序
for (int i = 0; i < [sortedArray count]; i++) {
NSArray *array = [[sortedArray objectAtIndex:i] sortedArrayUsingComparator:^NSComparisonResult(EMBuddy *obj1, EMBuddy *obj2) {
NSString *firstLetter1 = [ChineseToPinyin pinyinFromChineseString:obj1.username];
firstLetter1 = [[firstLetter1 substringToIndex:1] uppercaseString];
NSString *firstLetter2 = [ChineseToPinyin pinyinFromChineseString:obj2.username];
firstLetter2 = [[firstLetter2 substringToIndex:1] uppercaseString];
return [firstLetter1 caseInsensitiveCompare:firstLetter2];
}];
[sortedArray replaceObjectAtIndex:i withObject:[NSMutableArray arrayWithArray:array]];
}
NSLog(@"ssssssssss===%@",sortedArray);
return sortedArray;
}
Half12345