2012-02-21 41 views
0

我有我的應用程序一的tableview,我建的NIB,我通過大小檢查將高度設置爲68你在哪裏設置UITableView的高度或框架? AwakeFromNib?

我也做在我的代碼如下。

- (void) viewDidAppear:(BOOL)animated 
{ 
    self.tableView.frame = CGRectMake(0,0,320,68); 
    self.tableView.scrollEnabled = NO; 

} 

- (void)viewDidUnload 
{ 
    [super viewDidUnload]; 
} 

- (void)awakeFromNib 
{ 
    [self.tableView setBackgroundColor:[UIColor clearColor]]; 
    self.tableView.rowHeight = 68; 
} 

當我在模擬器或iPhone上運行應用程序時,它看起來很好,因爲表格只有68px高。如果我關閉了應用程序(進入主屏幕)並重新打開它,桌子不再只有68px高,但它佔據了整個屏幕。

我似乎無法讓它始終保持68px?

除了我上面的問題是否有一個方法(awakeFromNib,ViewDidAppear等),你應該始終只設置對象的大小或位置?

回答

0

找到自己的解決方案。每個Apple的解決方案是,如果您使用的是UITableView和其他子視圖,那麼不要使用uitbalviewcontroller,因爲tableview總是會嘗試使用整個屏幕。解決方法是使用uiview作爲uiviewcontroller的基礎,然後在uiview中放置一個uitableview,併爲uiviewcontroller提供管理tableview所需的委託方法。

所以,只要記住,如果你不想要一個完整的高度uitableview,那麼不要在菜單欄中使用uitableviewcontroller。

1

使用此方法來設置高度,

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
return 68; 
} 
0

把你的代碼放到viewWillApper,可工作!

- (void)viewWillAppear:(BOOL)animated 

{

[超級viewWillAppear中:動畫];

self.tableView.frame = CGRectMake(0,0,320,68); 
self.tableView.scrollEnabled = NO; 
[self.tableView setBackgroundColor:[UIColor clearColor]]; 
self.tableView.rowHeight = 68; 

}

相關問題