2011-02-17 40 views
0
self.tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain]; 

當我有UINavigationController和UITabBarController時,如何從視圖中獲取適當的大小?UINavigationController和UITableView框架問題

爲了避開它,我必須做的:

CGRect frame = self.view.frame; 
frame.origin.y -= [UIApplication sharedApplication].statusBarFrame.size.height; 
tableView = [[UITableView alloc] initWithFrame:frame style:UITableViewStylePlain]; 

我總是不得不手動設置我的意見/ tableviews的高度,以適應UINavigationController的內部,這真是煩人

這似乎有點奇怪,爲什麼它不會自動減去狀態欄高度?這是默認的樣式,而不是透明的狀態欄。

感謝

更新:如果我的Alloc了的tableView init方法後,只需設置幀self.view.frame工作正常。 Wuzzup智慧?

回答

1

在init方法之前設置UINavigationController的框架將不起作用,因爲UINavigationController尚未加載並顯示。該框架僅在控制器及其視圖被加載後才被設置。

您應該在UINavigationController的viewDidLoad方法中設置您的表(以及所有類似的初始化)。如果你這樣做,你就不會看到這類問題。

+0

或者,在加載視圖後,調用setNeedsLayout可以解決問題。 – 2011-02-18 02:27:06