gpt4 book ai didi

objective-c - UIPopoverController (contentSizeForViewInPopover) 中的动态 UITableView 高度?

转载 作者:太空狗 更新时间:2023-10-30 03:27:12 24 4
gpt4 key购买 nike

我有一个包含 UITableView 的 ipad 弹出窗口。填充表格后,它通常只有几个项目(4-5),所以我正在寻找一种方法将弹出窗口(contentSizeForViewInPopover)调整为实际表格高度(所有单元格的总高度)。

所以,我确实有高度,但我不确定在哪里调用 contentSizeForViewInPopover,我尝试调用它:viewDidAppearviewWillAppear 但没有成功,因为表格似乎是稍后填充的,实际高度仅在稍后可用。

对此有什么想法吗?谢谢!

编辑:我的单元格根据它们携带的内容具有不同的高度,我无法使用 noOfRows * cellHeight 预先计算高度。

最佳答案

当我的 View 看起来与 UITableView 匹配时,我想更改 contentSizeForViewInPopover 并且当我调用 reloadData 时,我只在以下情况下调用它删除或添加行或部分。

以下方法计算正确的高度和宽度并设置 contentSizeForViewInPopover

-(void) reloadViewHeight
{
float currentTotal = 0;

//Need to total each section
for (int i = 0; i < [self.tableView numberOfSections]; i++)
{
CGRect sectionRect = [self.tableView rectForSection:i];
currentTotal += sectionRect.size.height;
}

//Set the contentSizeForViewInPopover
self.contentSizeForViewInPopover = CGSizeMake(self.tableView.frame.size.width, currentTotal);
}

关于objective-c - UIPopoverController (contentSizeForViewInPopover) 中的动态 UITableView 高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6312821/

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