【问题标题】:tableFooterView not aligning itself properly at the bottom of the tabletableFooterView 未在表格底部正确对齐
【发布时间】:2014-03-12 09:55:03
【问题描述】:

我在使用 UITableView 时遇到了奇怪的行为。我用UITableView 设置了UIViewControllerUITableView 包含一个 tableHeaderViewtableFooterView、一个部分页脚视图和几个具有动态高度的 UITableViewCells。

问题是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;
}

【问题讨论】:

    标签: ios uitableview autolayout tablefooterview


    【解决方案1】:

    尝试设置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
    

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 所以,我不是唯一一个。很高兴知道。 :)
      • 我花了很长时间才意识到问题不是我的程序!!!认为框架可以开箱即用!
      【解决方案3】:

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

      【讨论】:

      • tableFooterView 对齐问题在 iOS 8.1 中仍然存在。您的解决方案有效......使用没有行的节标题。呵呵!!
      猜你喜欢
      • 2017-06-12
      • 2011-12-30
      • 2017-06-25
      • 1970-01-01
      • 2015-02-28
      • 1970-01-01
      • 2014-05-15
      • 2020-12-28
      • 1970-01-01
      相关资源
      最近更新 更多