5

我遇到了一个奇怪的行为UITableView。我已经UIViewControllerUITableView. UITableView包含一个tableHeaderView, tableFooterView, 一个节页脚视图和几个UITableViewCell具有动态高度的 s。

问题是它tableFooterView出现在表格中间的某个地方(悬停在单元格上),而不是在表格内容的底部对齐。显然,表格的contentSize属性也返回了不正确的内容大小(特别是高度)。

然而,自定义部分页脚视图出现在正确的位置(在实际的下方tableFooterView——悬停在表格中间)。

有什么想法吗?

注意:我的自定义表格视图(使用自动布局进行动态高度处理)显示“不明确的布局:2 个视图在垂直方向上不明确”。警告,但它在运行时正确调整大小。

表设置非常简单:

// Set table header/footer view
self.myTableView.tableHeaderView = self.myTableHeaderView;
self.mainTableView.tableFooterView = self.myTableFooterView;

// Table delegate methods
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [self heightForCellAtIndexPath:indexPath];
}

- (CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return [MyCustomCell defaultHeight];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {

    if (section == 0) {
        return self.mySectionFooterView;
    }

    return [UIView new];
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {

    if (section == 0) {
        return [self heightForSectionFooterView];
    }

    return 0.01f;
}
4

3 回答 3

3

尝试设置footerView.autoresizingMask = .flexibleWidth

示例代码:

let footerView = Bundle.main.loadNibNamed(String(describing: MyFooterView.self), owner: nil, options: nil)?.first as! MyFooterView
footerView.frame = CGRect(origin: .zero, size: CGSize(width: view.bounds.width, height: 80))
footerView.autoresizingMask = .flexibleWidth
tableView.tableFooterView = footerView
于 2017-04-12T14:27:31.780 回答
2

现在看起来像估计的HeightForRowAtIndexPath:与页脚视图混淆:

https://twitter.com/steipete/status/420538600384888832

于 2014-04-06T01:52:56.050 回答
1

我最终使用了一个只有页眉和页脚(没有行)的额外部分,以获得所需的结果。也许自动布局表现得很奇怪。我仍然收到“不明确的布局:2 个视图在垂直方向上不明确。”,但 UI 看起来不错。

于 2014-03-18T09:35:16.747 回答