转自:
https://blog.csdn.net/ndscoahz/article/details/78050027
https://www.jianshu.com/p/73394f7518c8
// tableView 偏移20/64适配
if
(
@available
(iOS
11.0
, *)) {
self
.
tableView
.
contentInsetAdjustmentBehavior
=
UIScrollViewContentInsetAdjustmentNever
;//UIScrollView也适用
}
else
{
self
.
automaticallyAdjustsScrollViewInsets
=
NO
;
}
// tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
- (
CGFloat
)tableView:(
UITableView
*)tableView heightForHeaderInSection:(
NSInteger
)section{
return
10
;
}
- (
CGFloat
)tableView:(
UITableView
*)tableView heightForFooterInSection:(
NSInteger
)section{
return
0.1
;
}
- (
UIView
*)tableView:(
UITableView
*)tableView viewForHeaderInSection:(
NSInteger
)section {
return
[[
UIView
alloc
]
init
];
}
- (
UIView
*)tableView:(
UITableView
*)tableView viewForFooterInSection:(
NSInteger
)section {
return
[[
UIView
alloc
]
init
];
}
手机在上午刚刚更新iOS11.0.2,本宝宝开发的app就出现了传说中导航栏不见的问题,当宝宝将更新好的xcode9.0打开并运行程序时,神奇的事情发生了,导航栏又正常了,但是我的页面的tableview间距发生了问题。如图1
抛出源代码如下:
// tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
如图3:
或者直接在AppDelegate.m文件中写全局适配,代码如下:
在iOS11中如果不实现-tableView: viewForHeaderInSection:和-tableView: viewForFooterInSection:
则-tableView: heightForHeaderInSection:和- tableView: heightForFooterInSection:不会被调用
导致它们都变成了默认高度,这是因为tableView在iOS11默认使用Self-Sizing
tableView的estimatedRowHeight、estimatedSectionHeaderHeight、estimatedSectionFooterHeight三个高度估算属性由默认的0变成了UITableViewAutomaticDimension,解决办法简单粗暴,就是实现对应方法或把这三个属性设为0。