gpt4 book ai didi

iphone - 确定 iPad 上 UITableView 的大小

转载 作者:行者123 更新时间:2023-11-29 13:39:03 25 4
gpt4 key购买 nike

我必须将表格的宽度分成 2、3、5 等份。目的是用 2、3、5 ... 等大小的方形 subview 填充表格单元格。 (图片)当然, table 的高度取决于此。

这就是我确定表格大小并将其除以要放置的图像数量的方法。numberOfPicsPerRow 方法返回用户选择在表的每一行中显示的图像数量的整数值。

- (CGFloat) rowHeight{

fcAppAppDelegate *delegate = (fcAppAppDelegate *);

CGRect bounds = self.tableView.bounds;
//CGRect bounds = self.view.bounds; // Alternative that returns the same result.
float tableWidth;
if (UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] delegate].tabBarController.interfaceOrientation))
tableWidth = bounds.size.width;
else
tableWidth = bounds.size.height;

NSLog (@"tableWidth: %f", tableWidth);
return tableWidth / [MatrixPhotoListTVC noOfPicsPerRow];
}

这是我第一次设置表格行高的地方:

- (void)viewDidLoad
{
[super viewDidLoad];

self.tableView.rowHeight = [self rowHeight];

}

在 iPhone 上一切正常。然而,在 iPad 上,tableView.bounds 或 view.bounds 返回 (width=320, heiht=372)。有趣的是,当设备旋转时,这些值是正确的。 (宽度=768,高度=960)

有人对此有解释吗? viewDidLoad 不是确定表大小的合适位置吗?

最佳答案

有时谈论它 - 在这种情况下写问题 - 会有所不同。

但是,这也可能发生在其他人身上,因此我将问题保留在系统中。这是答案:

viewDidLoad 在 View 被加载后立即被调用。这意味着在大多数情况下它是从 Nib 文件加载的。我使用的 nib 文件仅适用于 iPhone,不适用于 iPad 尺寸。这就是为什么 View 维度与它们在 IB 中完全相同的原因。

我将调用从 viewDidLoad 移到了 viewWillAppear,它在那里工作正常。显然,iOS 会在 viewDidLoad 和 viewWillAppear 的调用之间自动调整 iPad 的 View 大小(它做得很好)。

如果有人从学术或文档的角度知道我可以打电话的更好的地方,那么非常感谢提示。

然而,现在它似乎工作正常。

关于iphone - 确定 iPad 上 UITableView 的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9702429/

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