在 UIPopoverController 中显示 UItableViewController

发布于 2024-11-29 18:39:52 字数 137 浏览 3 评论 0原文

我正在 UIPopoverController 内显示 UITableViewController。一切工作正常,尽管 TableViewController 的大小非常大,即使只有 3-4 个单元格。我怎样才能使弹出窗口控制器的高度与表格视图的高度完全相同?

I am dispalying a UITableViewController inside a UIPopoverController. Everything works fine expect that the size of the TableViewController is very large even thought there are only 3-4 cells. How can I make it so the popover controller's height is exactly the same as tableview's height?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

依 靠 2024-12-06 18:39:52

您可以使用 UIPopoverController 的方法 - (void)setPopoverContentSize:(CGSize)sizeAnimated:(BOOL)animated 或使用 UIViewController 上的属性@property(nonatomic, readwrite) CGSize contentSizeForViewInPopover 来实现此目的。

You could use UIPopoverController's method - (void)setPopoverContentSize:(CGSize)size animated:(BOOL)animated or use the property on UIViewController @property(nonatomic, readwrite) CGSize contentSizeForViewInPopover to achieve this.

梦途 2024-12-06 18:39:52

重写 UITableViewControllercontentSizeForViewInPopover,如下所示:

- (CGSize)contentSizeForViewInPopover {
    // Currently no way to obtain the width dynamically before viewWillAppear.
    CGFloat width = 200.0; 
    CGRect rect = [self.tableView rectForSection:[self.tableView numberOfSections] - 1];
    CGFloat height = CGRectGetMaxY(rect);
    return (CGSize){width, height};
}

Override the contentSizeForViewInPopover of your UITableViewController like this:

- (CGSize)contentSizeForViewInPopover {
    // Currently no way to obtain the width dynamically before viewWillAppear.
    CGFloat width = 200.0; 
    CGRect rect = [self.tableView rectForSection:[self.tableView numberOfSections] - 1];
    CGFloat height = CGRectGetMaxY(rect);
    return (CGSize){width, height};
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文