2011-05-26 59 views
0

我有一個UITabbarcontroller有4個tabbar items.Each tabbar項目有UINavigationController.Activeually Tabbar從堆棧加載最後一個視圖控制器,而我切換下一個tabbar項目。UITabbarcontroller裏面的UINavigation控制器的問題

我想從堆棧中加載第一個視圖控制器,只要我在tabbar項目之間切換。

我該如何做到這一點?

+0

堆棧上的最後一個視圖控制器?它將顯示堆棧中最頂端的viewController。發佈一些代碼... – visakh7 2011-05-26 10:19:40

回答

0

您希望它在每個選項卡內回到根視圖控制器,而不是記住用戶在層次結構中的位置,每當切換選項卡時?

在切換選項卡時(即在選項卡欄控制器委託方法中),您需要在導航控制器上調用popToRootViewControllerAnimated:NO

0

您可以按照最好的辦法是:

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 {} 

,可以在其中設置選項卡名稱和圖像。
希望這會有所幫助。

相關問題