更新iOS11后 UITableView适配问题

2017-09-29  本文已影响0人  wxkkkkk

更新系统后项目页面出现了UITableView显示错位的两个问题

1.UITableView的顶部留白

iOS11下有问题的顶部


iOS11有问题.png

解决方法 去掉系统默认设置的边距

if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;//UIScrollView也适用
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }

解决后顶部留白消失


iOS11.png

2.UITableView显示多个Section 每个Section上下多出空隙

iOS11系统下 当UITableView初始化的style为UITableViewStyleGrouped时,显示多个Section会出现多余空隙

解决方法是把系统自带的上下view设置为nil

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    return nil;
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    return nil;
}

先写这两点 后续开发碰到在一一总结

上一篇 下一篇

猜你喜欢

热点阅读