ios开发之--ios11适配:TableView的heightForHeaderInSection设置高度无效/UISearchBar消失

更新到ios11,然后使用x-code9运行项目,发现tableview的-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section方法不走,所以页面也华丽丽的变成了一排的cell,通过查看文档和资料,原来是ios11默认开启self-sizing,把这个属性关系即可,

具体代码如下:

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

把上面这几句代码加到初始化tableview的地方即可,其他的设置不用变!加完后,再运行,原来的设置就起效了!

更新到ios11的话,会发现UISearchBar消失不见了,这个时候需要做如下修改即可:

新建一个UIView类,实现如下方法即可:

-(CGSize)intrinsicContentSize
{
    return UILayoutFittingExpandedSize;
}

以上方法亲测有效!

原文地址:https://www.cnblogs.com/hero11223/p/7685511.html