我有一个UIViewController
,其中有3个UITableView
垂直排列。我不希望任何表格滚动。两个表格(A
和B
)的高度正在根据其内容进行计算 - 第三个(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
,但控制器设置作为<UITableViewDataSource,UITableViewDelegate,...>
在MyViewController.h
文件中。 为了使用此代码,我需要实现heightForHeaderInSection
吗?如果是这样,是否有一种方法可以实现它,并强制它返回一些默认值(如return [super heightForHeader];
)?如果没有,为什么我得到这个错误?
是的,我使用'contentSize'来设置我在发布的代码中提到的NSLayoutConstraint,并且我选中了禁止在Storyboard上滚动的框,所以这也被照顾了。我正在寻找的是如何缩小表格“C”中的单元格,使它们都适合我拥有的空间。我认为'UIScrollView'上没有任何东西可以帮助我,除非我错过了一些东西。 – GeneralMike