我得把桌子的宽度分成2,3,5,...相等的部分。其目的是用2,3,5,...填充表格单元格大小相等的正方形子视图。(图片)当然,桌子的高度取决于此。
这就是我如何确定表的大小,并将其除以要放置的图像的数量。方法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不是确定表格大小的合适位置吗?
发布于 2012-03-14 21:20:00
我会将您的代码切换到-viewWillAppear或-viewDidAppear方法,因为表视图已经完成了任何布局。
如果UITableView被子类化,另一种可能是对方法进行子类化:
- (void)layoutSubviews {
[super layoutSubviews];
....
}https://stackoverflow.com/questions/9702429
复制相似问题