代码之家  ›  专栏  ›  技术社区  ›  Mustafa

tableFooterView未在表格底部正确对齐

  •  5
  • Mustafa  · 技术社区  · 11 年前

    我正在经历一种奇怪的行为 UITableView 。我已经设置了 UIViewController 用一个 UITableView(UITableView) . UITableView(UITableView) 包含 tableHeaderView , tableFooterView 、节页脚视图和一些 UITableViewCell s的动态高度。

    问题是 表页脚视图 出现在表格中间的某个位置(悬停在单元格上),而不是在表格内容的底部对齐自身。显然,桌子 contentSize 属性也返回了不正确的内容大小(特别是高度)。

    但是,自定义节页脚视图显示在正确的位置(并且位于实际的下方 表页脚视图 --它在桌子中间徘徊)。

    知道发生什么事了吗?

    注意:我的自定义表视图(使用自动布局进行动态高度处理)显示“不明确布局: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;
    }
    
    3 回复  |  直到 11 年前
        1
  •  3
  •   Yakiv Kovalskyi zoul    8 年前

    尝试设置 footerView.atoresizingMask=.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
  •  2
  •   Ben Jackson    11 年前

    看起来像现在估计的HeightForRowAtIndexPath:页脚视图出错:

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

        3
  •  1
  •   Mustafa    11 年前

    我最后使用了一个只有页眉和页脚(没有行)的额外部分,以获得所需的结果。也许汽车布局很奇怪。我仍然得到“模糊布局:2个视图垂直模糊”,但UI看起来不错。

    推荐文章