gpt4 book ai didi

ios - 动态调整UITableView高度

转载 作者:行者123 更新时间:2023-12-01 19:00:30 25 4
gpt4 key购买 nike

如何动态调整UITableView的高度?假设我有3行,每行的高度为65。将新行添加到UITableView时,我希望它动态调整其高度以适合新行。反之亦然,当删除行以缩小时。

最佳答案

编辑:误读

这取决于tableview.frame.size.height(表格单元格行的高度*表中的行数)。

好吧,我建议这样。

-(void)correctHeight
{

//Note : if all cells are having common value
CGFloat heightOfCell=[table rowHeight];

CGFloat expectedHeightOfTable=0;
for (int i=0; i< [table numberOfSections]; i++) {
//header section
CGFloat heightOfHeaderView=[table headerViewForSection:i].frame.size.height;
expectedHeightOfTable = expectedHeightOfTable +heightOfHeaderView;

//content section
expectedHeightOfTable = expectedHeightOfTable + heightOfCell*[table numberOfRowsInSection:i];
}
[table setFrame:CGRectMake(table.frame.origin.x, table.frame.origin.y, table.frame.size.width,expectedHeightOfTable)];


}

这将考虑标题和每一行的内容以及按比例填充的所有值。因此,无需添加一些硬编码值

关于ios - 动态调整UITableView高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23240761/

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