表视图为Group类型的注意问题

时间:2025-04-14 13:05:33

使用group类型的tableview时,第一个section距离navigationbar的距离很大,不符合这边的设计图。

使用 myTableView . sectionHeaderHeight = 0.0001f无效。

于是通过各种方法测试,终于得到解决方法。就是通过设置tableview的headerview高度来控制这个距离。使用的方法是:代理

之前的写法是这样:

 //创建表视图
- (void)_creatTableView
{ _myTableView = [[UITableView alloc]initWithFrame:CGRectMake(,, kScreenWidth, kScreenHeight) style:UITableViewStyleGrouped]; _myTableView.delegate = self;
_myTableView.dataSource = self;
_myTableView.sectionFooterHeight = 0.00001f;
_myTableView.sectionHeaderHeight = 0.00001f;
_myTableView.backgroundColor = [UIColor redColor]; [_myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:identy]; [self.view addSubview:_myTableView];
}

正确是这样: 不知道这是iOS的bug呢还是什么,总之解决方法就是以下:

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {

    return 0.0001f;
}