iOS:UITableView底部的额外空间

iOS:UITableView底部的额外空间,ios,objective-c,uitableview,Ios,Objective C,Uitableview,我以编程方式创建了UITableView,但它下面有一些额外的空间(精确地说是29像素) 以下是初始化表的方式: UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain]; [tableView setTranslatesAutoresizingMaskIntoConstraints:NO]; [self.contentView addSubview:ta

我以编程方式创建了
UITableView
,但它下面有一些额外的空间(精确地说是29像素)

以下是初始化表的方式:

UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[self.contentView addSubview:tableView];
self.alertsTableView = tableView;
以下是限制条件:

    @"V:|-10-[_alertsTableView(0)]-5-[_optionsLabel]",
    @"H:|-15-[_alertsTableView]-15-|", 
我尝试将页脚视图设置为零,并将其高度返回零:

[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return CGFLOAT_MIN;
}
我会根据内容动态更改其高度:

- (void)updateHeight:(CGFloat)height {
    if (self.tableView.superview) {
        NSLayoutConstraint *heightConstraint;
        for (NSLayoutConstraint *constraint in self.tableView.superview.constraints) {
            if (constraint.firstAttribute == NSLayoutAttributeHeight) {
                heightConstraint = constraint;
                break;
            }
        }
        heightConstraint.constant = height;
    }
}

我还将
setAutomaticallyAdjustsScrollViewInsets
设置为
NO
。这是最终的结果。单元格和空白之间有分隔符,但底部不是单元格

您可以使用contentInset来补偿29px额外的底部边距:

tableView.contentInset = UIEdgeInsetsMake(0, 0, -29, 0);

尝试添加
表格视图页脚视图

tableView.tableFooterView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))

也可以使用设置footerview。table.tableFooterView=[uiview新建];尝试“调试视图层次结构”按钮-可能会帮助您查看哪个UIView占用了空间。您是否可以分享如何计算高度的代码。此外,我还建议更改更新约束的方法。您不必运行所有约束,而是可以首先使用高度约束的ivar,并可以在
updateHeight:
方法中直接更新其值。@Gandalf我只是在
CellForRowatinePath:
中将其设置为等于
contentSize.height
。我将研究您的建议,问题是,所有这些都发生在三个不同的类之间(委托方法位于单独的委托类、viewcontroller和视图中,表位于其中,它是viewcontroller的子视图)。您可能需要设置contentInset值。选中此项: