2011-05-25 107 views
1

我有一個基於視圖的應用程序,其中在第一個視圖中我不希望tabbar控制器和視圖以外的視圖(即從第二個視圖..)我想有tabbar控制器。 我GOOGLE了它,但無法得到一個解決方案。如何將uitabbarcontroller添加到uiviewcontroller

+0

您好,我有同樣的issue.Canü請幫助我ü是如何解決這個問題 – 2012-09-13 05:22:12

回答

1

您需要從基於視圖的應用程序開始。然後在你的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 {} 

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

+2

你好,通過[窗口addSubview :tabBarController.view];它會添加從firstview tabbar,但我想添加標籤欄來回第二視圖controller.Please幫助我。 – 2012-09-13 05:23:13

相關問題