你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
搜索问题、话题或人...
输入关键字进行搜索
搜索:
问题
精选文章
开源项目
视频教程
活动
· · ·
帮助
登录
注册
环信_iOS
ios demo 好友列表拼音搜索问题
没有找到相关结果
已邀请:
与内容相关的链接
提交
2 个回复
[已注销]
有什么问题么
不轻易言弃
有的,出现上面的效果,我代码这样模仿你们写,传入装着好友名字的数组,没效果
if (goodFriendName.count!=0) {
for (TXGoodFriendModel *goodFriendModel in goodFriendName) {
NSString *firstLetter = [ChineseToPinyin pinyinFromChineseString:goodFriendModel.nickname];
NSInteger section = [indexCollation sectionForObject:[firstLetter substringToIndex:1] collationStringSelector:@selector(uppercaseString)];
NSMutableArray *array = [sortedArray objectAtIndex:section];
[array addObject:goodFriendModel];
}
}
for (int i = 0; i < [sortedArray count]; i++) {
NSArray *array = [[sortedArray objectAtIndex:i] sortedArrayUsingComparator:^NSComparisonResult(TXGoodFriendModel *obj1, TXGoodFriendModel *obj2) {
NSString *firstLetter1 = [ChineseToPinyin pinyinFromChineseString:obj1.nickname];
firstLetter1 = [[firstLetter1 substringToIndex:1] uppercaseString];
NSString *firstLetter2 = [ChineseToPinyin pinyinFromChineseString:obj2.nickname];
firstLetter2 = [[firstLetter2 substringToIndex:1] uppercaseString];
return [firstLetter1 caseInsensitiveCompare:firstLetter2];
}];
[sortedArray replaceObjectAtIndex:i withObject:[NSMutableArray arrayWithArray:array]];
}
DLog(@"ssssssssss===%@",sortedArray);
//名字分section
for (EMBuddy *buddy in dataArray) {
//getUserName是实现中文拼音检索的核心,见NameIndex类
DLog(@"拼音===%@",buddy.username);
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内的数组排序
// DLog(@"ssssssssss===%@",sortedArray);
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]];
}
要回复问题请先
登录
或
注册
发起人
不轻易言弃
问题状态
最新活动:
2015-08-13 14:47
浏览:
4297
关注:
2
人
2 个回复
[已注销]
不轻易言弃
if (goodFriendName.count!=0) {
for (TXGoodFriendModel *goodFriendModel in goodFriendName) {
NSString *firstLetter = [ChineseToPinyin pinyinFromChineseString:goodFriendModel.nickname];
NSInteger section = [indexCollation sectionForObject:[firstLetter substringToIndex:1] collationStringSelector:@selector(uppercaseString)];
NSMutableArray *array = [sortedArray objectAtIndex:section];
[array addObject:goodFriendModel];
}
}
for (int i = 0; i < [sortedArray count]; i++) {
NSArray *array = [[sortedArray objectAtIndex:i] sortedArrayUsingComparator:^NSComparisonResult(TXGoodFriendModel *obj1, TXGoodFriendModel *obj2) {
NSString *firstLetter1 = [ChineseToPinyin pinyinFromChineseString:obj1.nickname];
firstLetter1 = [[firstLetter1 substringToIndex:1] uppercaseString];
NSString *firstLetter2 = [ChineseToPinyin pinyinFromChineseString:obj2.nickname];
firstLetter2 = [[firstLetter2 substringToIndex:1] uppercaseString];
return [firstLetter1 caseInsensitiveCompare:firstLetter2];
}];
[sortedArray replaceObjectAtIndex:i withObject:[NSMutableArray arrayWithArray:array]];
}
DLog(@"ssssssssss===%@",sortedArray);
//名字分section
for (EMBuddy *buddy in dataArray) {
//getUserName是实现中文拼音检索的核心,见NameIndex类
DLog(@"拼音===%@",buddy.username);
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内的数组排序
// DLog(@"ssssssssss===%@",sortedArray);
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]];
}