美文网首页
iOS tableView 顶部留白的问题

iOS tableView 顶部留白的问题

作者: wahkim | 来源:发表于2018-02-08 14:39 被阅读27次
前言:今天产品大大,说boss安装了app之后首页底部有处留白的问题,如下图 WX20180208-142639.png

看到这个问题,其实我已经清楚了个问题的大概,boss的ipone手机系统是10.3的,可关键是我在编写代码的时候就已经适配了该系统,代码如下面

if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return [[UIView alloc]init];
    }
}

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

看到问题了没有,如果没有下面就是解决问题的关键所在

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section == 0) {
        return 0.001;//把高度设置为0.001就解决了(为0的时候,他会使用默认值))
    }
    return 100;
}

如果分区的尾部视图也适用。

如果你不想实现viewForHeaderInSection也不想留白,那么只需要你把self-sizeing自动估高关闭即可
自动关闭估算高度,不想估算那个,就设置那个即可

self.tableView.estimatedRowHeight = 0
self.tableView.estimatedSectionHeaderHeight = 0
self.tableView.estimatedSectionFooterHeight = 0

相关文章

网友评论

      本文标题:iOS tableView 顶部留白的问题

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