我必须将表格的宽度分为2,3,5等等部分。目的是用2,3,5,...等大小的方形子视图填充表格单元格。 (图片) 当然,桌子的高度取决于此。确定iPad上UITableView的尺寸
这是我如何确定表的大小,并根据要放置的图像数来划分它。 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)。 有趣的是,当设备旋转时,这些值是正确的。 (width = 768,height = 960)
有没有人对此有过解释? viewDidLoad不是确定表格大小的合适位置吗?
。在'viewDidLoad:'视图刚刚加载时,它与您在IB中创建的视图相同,包括大小。然后,在将视图添加到视图层次结构之前,将根据自动调整屏蔽来调整视图大小,然后调用viewWillAppear:,然后添加视图。这就是为什么'viewDidLoad:'dimension *应该*对当前视图层次结构正确。 – Pascal 2012-03-14 13:23:03