UITableView 防止自动偏移

// tableView 不随导航栏偏移
if (@available(iOS 11.0, *)) {
self.tbView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
} else{
self.automaticallyAdjustsScrollViewInsets = NO;
}

  • 使用UITableViewStyleGrouped 类型的UITableView
    在使用此类UITableView 时,也会发生自动偏移的情况,存在的情况:UITableViewCell 向下偏移 35;因为在实现的时候,会自动设置UITableView Herder 的高度,所以需要自己设置其Header 高度为 CGFLOAT_MIN;

    解决办法:

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

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

你可能感兴趣的:(UITableView 防止自动偏移)