iOS中的二级菜单及Cell的展开收起示例

2020-01-21 00:34:04丽君

(3)在手势响应事件中根据headerview的标识选择展开还是收起row,且改变标识


-(void)sectionClick:(UITapGestureRecognizer *)tap{
//根据tag值获取点击的区
  int index = tap.view.tag%100;
//创建可变数据,存储所点击的区的所有行的indexpath,tableview刷新区对应的行,重新设置行高
  NSMutableArray *indexArray = [[NSMutableArray alloc]init];
  NSArray *arr = specificArr[index];
  for (int i = 0; i<arr.count; i++) {
    NSIndexPath *path = [NSIndexPath indexPathForRow:i inSection:index];
    [indexArray addObject:path];
  }
  //展开
  if ([flagArr[index] isEqualToString:@"0"]) {
    [flagArr replaceObjectAtIndex:index withObject:@"1"];
    [specificTable reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationBottom];
  }else{
    [flagArr replaceObjectAtIndex:index withObject:@"0"];
    [specificTable reloadRowsAtIndexPaths:indexArray withRowAnimation:UITableViewRowAnimationBottom];
  }
}

(4)在tableView heightForRowAtIndexPath方法中设置tableview的高度


 if ([flagArr[indexPath.section] isEqualToString:@"0"]) {
      return 0;
    }else{
      return 96;
    }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持ASPKU。


注:相关教程知识阅读请移步到IOS开发频道。