注册

ios demo 好友列表拼音搜索问题



D54CB2CE-C04A-40F9-9D0F-D8F675C496C2.png


 
已邀请:
有什么问题么
 
有的,出现上面的效果,我代码这样模仿你们写,传入装着好友名字的数组,没效果
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]];

    }
 

要回复问题请先登录注册