tableview 按字母排序分区 并加对应副标题

  self.collation = [UILocalizedIndexedCollation currentCollation];

    

    NSUInteger sectionTitlesCount = [_collation.sectionTitles count];

    self.outerArray = [NSMutableArray arrayWithCapacity:sectionTitlesCount];

    for (NSUInteger index = 0; index < sectionTitlesCount; index++)

    { NSMutableArray *array = [NSMutableArray array];

        [self.outerArray addObject:array];

    }


    for (int i = 0; i < [_tableData count]; i++){

        NSDictionary *myDic = [_tableData objectAtIndex:i];

        NSInteger sectionNumber = [_collation sectionForObject:[myDic objectForKey:@"UserName"] collationStringSelector:@selector(lowercaseString)];

        NSMutableArray *sectionNames = [_outerArray objectAtIndex:sectionNumber];

        [sectionNames addObject:myDic];

    }  //用字典替换 string, 字典里是 UserName:人名  OrgName:  部门

//    for (NSString *nameString in [_tableData valueForKey:@"UserName"])

//    {

//        NSInteger sectionNumber = [_collation sectionForObject:nameString collationStringSelector:@selector(lowercaseString)];

//        NSMutableArray *sectionNames = [_outerArray objectAtIndex:sectionNumber];

//        [sectionNames addObject:nameString];

//    }  用上边的替换了。


    for (NSUInteger index = 0; index < sectionTitlesCount; index++)

    {

        NSMutableArray *namesForSection = [_outerArray objectAtIndex:index];

        NSMutableArray *mkNameArray = [[NSMutableArray alloc]init];

        for (int i = 0; i< [namesForSection count]; i++){

            NSString *nameString = [[namesForSection objectAtIndex:i]objectForKey:@"UserName"];

            [mkNameArray addObject:nameString];

        }

        NSMutableArray *sortedNamesForSection = [NSMutableArray arrayWithArray:[_collation sortedArrayFromArray:mkNameArray collationStringSelector:@selector(lowercaseString)]];

        [mkNameArray release];

        

        int m;

        for (m = 0; m < [sortedNamesForSection count]; m++){

            NSString *sortedName = [sortedNamesForSection objectAtIndex:m];

            

            for (int n =0; n< [namesForSection  count]; n++){

                NSString *namesInDic = [[namesForSection objectAtIndex:n]objectForKey:@"UserName"];

                if ([sortedName isEqualToString:namesInDic]){

                    [sortedNamesForSection replaceObjectAtIndex:m withObject:[namesForSection objectAtIndex:n]];

                }

            }

        }

        [self.outerArray replaceObjectAtIndex:index withObject:sortedNamesForSection];

    }添加了副标题, 每个分区内的排序要重新设计

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值