UITableViewCell 折叠与展开

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yaojinhai06/article/details/76152146


需求:

   一级列表展示分类,二级类表显示分类的具体详细信息:

   比如: 一级列表显示: 北京,天津,上海等,

           二级列表 点击北京显示 朝阳区,海淀区,玄武区,等等

          但是只有一个是展开的,如果北京市展开那么其他都要折叠.

      

      主要方法:

- (void)didSelecterSection:(AddressTableHeader*)header{
    
    NSInteger tag = header.tag;

    // 第一步
    if (selectedSection != tag && selectedSection != -1) {
        exentenDict[@(selectedSection)] = @(false);

        NSIndexSet *set = [[NSIndexSet alloc]initWithIndexesInRange:NSMakeRange(selectedSection, 1)];
        [_chooseLocationView.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationAutomatic];

    }
    
    // 第二步
    
    BOOL exten = exentenDict[@(tag)].boolValue;
    exentenDict[@(tag)] = @(!exten);
    
    NSIndexSet *set = [NSIndexSet indexSetWithIndex:tag];
    
     [_chooseLocationView.tableView reloadSections:set withRowAnimation:UITableViewRowAnimationAutomatic];
    
    selectedSection = tag;

}


注意顺序:

必须先判断是否是点击的与上次的是同一行,如果是先要把上一行折叠,然后才可以展开下一行,如果不是则直接展开当前行.好了如果还有问题可以随时咨询.






猜你喜欢

转载自blog.csdn.net/yaojinhai06/article/details/76152146