今天将Xcode和iPhone分别升级到Xcode9和iOS11运行了一下项目,发现有的TableView的Header不见了,多个分组变成了一组。而且还多出了一些分割线。
没有数据时不显示tableView的分割线:
_tableView.tableFooterView = [[UIView alloc] init];
tableView的 Header、 Footer设置
// tableView 如果是Gruop类型的话,section之间的间距变宽,执行返回高度的同时还需要执行return UIView的代理
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 10;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
return [[UIView alloc] init];
}
将上述代码添加到类中,再继续运行就好了。
tableView自动设置内边距修改
// tableView 偏移20/64适配
if (@available(iOS 11.0, *)) {
self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
}
else {
self.automaticallyAdjustsScrollViewInsets = NO;
}
automaticallyAdjustsScrollViewInsets,当设置为YES时(默认YES),如果视图里面存在唯一一个UIScrollView或其子类View,那么它会自动设置相应的内边距,这样可以让scroll占据整个视图,又不会让导航栏遮盖。当
controller上的第一个子视图不是scrollview以及其子类的时候,就会取消内边距。此时原本全屏的scrollview设置的frame(0,0,self.view.frame.size.width,xx)就会从状态栏开始算起,如果应用有导航栏的话,那么就会遮盖住视图的64个高度解决方案:
self.automaticallyAdjustsScrollViewInsets = NO;禁用掉自动设置的内边距,自行控制controller上index为0的控件以及scrollview控件的位置
self.edgesForExtendedLayout = UIExtendedEdgeNone;这种方式设置,不需要再重新设置index为0的控件的位置以及scrollview的位置,(0,0)默认的依然是从导航栏下面开始算起作者:天清水蓝
链接:http://www.jianshu.com/p/75fd23bb5286
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。









网友评论