UIPopoverController中的动态UITableView高度(contentSizeForViewInPopover)? [英] Dynamic UITableView height in UIPopoverController (contentSizeForViewInPopover)?

查看:132
本文介绍了UIPopoverController中的动态UITableView高度(contentSizeForViewInPopover)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an ipad popover that contains an UITableView. After the table is populated, it usually has a few items in it only (4-5), so I'm looking for a way to resize the popover (contentSizeForViewInPopover) to the actual table height (the summed height of all its cells).

所以,我确实有高度,但我不知道在哪里调用 contentSizeForViewInPopover ,我试过调用它: viewDidAppear viewWillAppear 但没有成功,因为看起来表后面填充和实际高度

So, I do have the height but I'm not sure where to call contentSizeForViewInPopover, I did try to call it in: viewDidAppear and viewWillAppear but with no success since it seems that the table gets populated later and the actual height is only available later.

对此有任何想法吗?谢谢!

Any thoughts on this? Thanks!

编辑:我的单元格有不同的高度基于他们携带的内容,我不能预先计算高度与 noOfRows * cellHeight c>。 c。

My cells have different heights based on the content they carry, I can't pre-calculate the height with noOfRows * cellHeight.

推荐答案

我想改变 contentSizeForViewInPopover 当我的视图看起来与 UITableView 匹配时,以及当我调用 reloadData 添加行或部分。

I wanted to change the contentSizeForViewInPopover when my view appeared to match the UITableView and also when I call reloadData as I only call this when removing or adding rows or sections.

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

The following method calculates the correct height and width and sets the 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);
}

这篇关于UIPopoverController中的动态UITableView高度(contentSizeForViewInPopover)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆