2011-05-04 70 views
1

我想創建一個視圖,頂部有一個導航欄,uitableview作爲內容,底部有一個uitabbar。我想以編程方式創建所有這些,而不必使用xib ..我該怎麼做?UINavigationController和UITableView

到目前爲止,我有:

@interface GroupViewController : UINavigationController <UITableViewDelegate, UITableViewDataSource>{ 
    UITableView * table; 
    UITabBar * bar; 

} 

@property (nonatomic, retain) UITableView * table; 
@property (nonatomic, retain) UITabBar * bar; 

@end 

的UITabBarItem點擊會出現一個彈出窗口(非切換視圖,因爲如果是這樣的話,那麼我就需要一個UITabBarViewController)時。

我的擔心之一是我在哪裏指定UITabBar在這個整體視圖中的位置?在UIViewDidLoad中?

回答

0

您需要從基於視圖的應用程序開始。然後在你的appDelegate文件中創建一個UITabbarController。

Appdelegate.h 

UITabBarController *tabBarController; 
// set properties 


Appdelegate.m 

// Synthsize 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.delegate=self; 

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController 
Search * search = [[Search alloc] init]; 
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search]; 

Nearby* nearby = [[Nearby alloc] init]; 
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby]; 

Map* map = [[Map alloc] init]; 
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map]; 

AboutUs* aboutUs = [[AboutUs alloc] init]; 
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs]; 

Favorites* favorites = [[Favorites alloc] init]; 
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites]; 

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil]; 

tabBarController.viewControllers = controllers;

[window addSubview:tabBarController.view];  

您可以相應地管理在哪個選項卡中放置導航控制器或只有視圖控制器。

在上述各你所提到的視圖控制器的

然後需要實現

- (id)init {} 

,可以在其中設置選項卡名稱和圖像。

+0

你誤解了我的問題......正如我說的,當我點擊UITabBarItem時,它不會加載一個新的視圖..只是一個彈出窗口..我是否還需要一個UITabBarController?即:UITableView永久存在,無論您按什麼UITabBarItem – adit 2011-05-04 05:06:38

+0

是的。你需要用UITabBarController啓動你的應用程序。我不知道爲什麼你的標籤欄項目不顯示你想要的。爲此,我需要看到更多的代碼。但試試這樣實現吧。 – Nitish 2011-05-04 05:12:06

0

在loadview方法中創建所有東西(導航欄,uitableview,tabbar)。

+0

我必須在loadview中進行分配嗎? – adit 2011-05-04 05:10:33

相關問題