我必須將表格的寬度分爲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