2010-08-04 41 views
0

我有一個頂部有導航欄的應用程序。有一種意見認爲這是UITableView的子類,我添加的UITableView下方UIToolbar用下面的代碼:幫助使用UIToolbar修復UIViewController

UIToolbar *toolbar = [[UIToolbar alloc] init]; 
[toolbar sizeToFit]; // Set the toolbar to fit the width of the app 
CGFloat toolbarHeight = [toolbar frame].size.height; // Calculate the height of the toolbar 
CGRect rootViewBounds = self.parentViewController.view.bounds; 
CGFloat rootViewHeight = CGRectGetHeight(rootViewBounds); 
CGFloat rootViewWidth = CGRectGetWidth(rootViewBounds); 
CGRect rectArea = CGRectMake(0, toolbarHeight, rootViewWidth, toolbarHeight); 
[toolbar setFrame:rectArea]; 
[self.navigationController.view addSubview:toolbar]; 

的問題是,該工具欄是「上面」的UITableView的和被掩蓋在頂部UITableView中第一行的內容。我真正想要的是讓桌面視圖在UIToolbar下面「開始」。

我該如何適當地完成這項工作?

格拉西亞斯, 何塞

回答

0

我同意nonamelive,但如果有理由需要你描述的邏輯。您應該使用UITableView子視圖和工具欄子視圖使視圖成爲一個普通的視圖,並相應地設置它們的框架以根據需要定位它們。

如果您希望工具欄與其他表格內容一起滾動,另一個選項是使表格的headerView工具欄。

0

在我看來,初始化一個新的工具欄就是錯誤的路要走。

只需使用這個簡單的代碼,因爲你已經有了一個UINavigationController。

- (void)viewDidLoad { 
    self.navigationController.toolbar.hidden = NO; 
} 

對不起,錯了代碼。試試這個吧!

- (void)viewDidLoad { 
    self.navigationController.toolbarHidden = NO; 
} 
+0

嗯。這在'viewDidLoad'中沒有做任何事情,但是如果我將這段代碼附加到一個按鈕上,那麼它確實可行。爲什麼會這樣? – 2010-08-04 02:51:19

+0

嗨,我已經更新了代碼。對不起,錯誤的代碼。 :) – nonamelive 2010-08-04 03:22:36