美文网首页
UITableview 分组高度设置为0.01会出现一根线

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

作者: 倒着游的鱼 | 来源:发表于2021-07-22 10:12 被阅读0次

在之前,当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;   
}

相关文章

网友评论

      本文标题:UITableview 分组高度设置为0.01会出现一根线

      本文链接:https://www.haomeiwen.com/subject/ocvumltx.html