iOS11适配table的区头高度

来源:互联网 发布:中国房产数据 编辑:程序博客网 时间:2024/05/17 01:56

升级到iOS11之后,之前写的table代码没有做任何调整,突然发现自己设置的区头高度10pt就没了,也就是本方法不起作用

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

但使用iOS10,iOS9系统的iPhone都试了一下,发现都是有区头高度的,因此猜测是iOS11系统问题

在iOS11中如果不实现-tableView: viewForHeaderInSection:和-tableView: viewForFooterInSection:
则-tableView: heightForHeaderInSection:和- tableView: heightForFooterInSection:不会被调用
导致它们都变成了默认高度,这是因为tableView在iOS11默认使用Self-Sizing
tableView的estimatedRowHeight、estimatedSectionHeaderHeight、estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension,解决办法如下代码:

if (@available(iOS 11.0, *)) {        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;        // est和代理 可选1个        self.tableView.estimatedSectionHeaderHeight = 10;    } else {        self.automaticallyAdjustsScrollViewInsets = NO;    }






原创粉丝点击