gpt4 book ai didi

ios - 计算固定行数和表格高度的行高

转载 作者:行者123 更新时间:2023-11-29 10:50:35 25 4
gpt4 key购买 nike

我有一个 UIViewController与 3 UITableView s 垂直排列在上面。我不希望任何表格滚动。其中两个表格(AB)的高度是根据其内容计算的——第三个表格(C)将重新调整大小以适应屏幕上剩余的任何空间。对于 C , 我会知道我需要显示多少行,我想计算出正确的 heightForRowAtIndexPath使所有的单元格都适合。

现在,我正在努力

  • 取整个屏幕的高度
  • 减去 A 的总高度
  • 减去 B 的总高度
  • 减去一些固定的空格
  • 减去 C 的大小的标题
  • 减去 C 的大小的页脚
  • 除以 C 中的单元格数

根据我的计算,这应该让我获得 C 中每个单元格所需的高度。 . 对吗?有什么我遗漏的吗?这是我正在使用的代码:

- (CGFloat) tableView:(UITableView *) heightForRowAtIndexPath:(NSIndexPath *)indexPath
{

if (tableView = self.tableC)
{

// self.lcA & self.lcB are NSLayoutContraints that I'm setting after I calculate how tall those tables need to be
// buffer is some white space padding I add to keep the tables from touching - it will be hardcoded to some constant before this code runs

CGFloat target = (self.view.bounds.size.height - self.lcA.constant - self.lcB.constant - [self tableView:tableView heightForHeaderInSection:indexPath.section] - [self tableView:tableView heightForFooterInSection:indexPath.section] - buffer) / [self tableView:tableView numberOfRowsInSection:indexPath.section];

}

}

但是,当我运行它时,它崩溃了,显示 -[MyViewController tableView:heightForHeaderInSection:]: unrecognized selector sent to instance

我没有明确实现 heightForHeaderInSection在这个特定的 View Controller 上,但 Controller 设置为 <UITableViewDataSource,UITableViewDelegate,...>MyViewController.h文件。 我需要实现 heightForHeaderInSection 吗?为了使用这个代码?如果是这样,有没有一种方法可以实现它并强制它返回一些默认值(类似于 return [super heightForHeader]; )?如果不是,为什么会出现此错误?

最佳答案

而不是做“- [self tableView:tableView heightForFooterInSection:indexPath.section]”和所有这些东西,我认为你可以通过这个访问标题高度:

self.tableA.sectionHeaderHeight

对于页脚:

self.tableA.sectionFooterHeight

你还有:

self.tableA.tableHeaderView
self.tableA.tableFooterView

您可以在苹果文档中更好地了解所有这些内容:TableView Doc

关于ios - 计算固定行数和表格高度的行高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20636357/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com