0
点赞
收藏
分享

微信扫一扫

UITableview 分组高度设置为0.01会出现一根线

在觉 2021-09-19 阅读 78
日记本

在之前,当tableView.style = UITableViewStyleGrouped的时候,设置sectionHeader和sectionFooter的高度为0的时候,往往设置0不管用<iOS10>,会设置个0.01。为了封装方便,可能有的时候当tableView.style = UITableViewStylePlain的时候,也会这么干。
这样就会使得tableView.style = UITableViewStyleGrouped/UITableViewStylePlain的时候让sectionHeader和sectionFooter的高度看不到了
但是在iOS14,就会出现上面说的那种情况,当然了tableView.style = UITableViewStyleGrouped不受影响

适配方案:
1、当tableView.style = UITableViewStylePlain
iOS10~iOS14通用
都 return 0;

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 0;
}
 

2、如果当前封装的tableView两种类型都有,那么进行相关的判断

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
   
    if (tableView.style == UITableViewStyleGrouped) {
    return 0.01;
   }
    return 0;   
}
举报

相关推荐

0 条评论