2014-02-12 73 views
0

我正在爲我的應用程序使用UITabbarControllerUINavigationController。我已經創建了應用程序與UITabbar基礎應用程序,它是我給不同類型的導航控制器導航視圖。如下圖所示。 enter image description here如何將viewcontroller移動到tabbar項目上的rootViewController點擊

但我有1個問題,我描述如下:

假設我有5 ViewController和3 NavigationViewController對於所有五個視圖控制器等視圖1爲rootViewController和視圖2爲子視圖。查看3爲RootViewController第二個NavigationViewController和查看4爲subview第三個RootViewController等。

當我在當時運行應用程序view1加載爲RootViewController現在我導航到查看2,因爲它是當時的視圖1的子視圖我的標籤欄選擇到第一個選項卡。當我點擊第二個標籤欄按鈕時,它顯示我查看3爲RootViewController第二個NavigationController

現在我回到第一個Tabbar按鈕查看視圖1,但它顯示我子視圖2.如果我需要移動到RootViewController我需要按回來按鈕來查看我的RootView

所以根據我的sinario可以設置RootView爲特定的標籤欄,這樣用戶可以很容易地去RootView沒有查看所有標籤欄點擊項目的子視圖。

請幫幫我。

+0

你的意思是當你點擊你的標籤欄按鈕時,它應該顯示你的導航控制器的根視圖控制器? – jailani

+0

是@jai你是對的。 –

回答

0

使用此代碼。當你點擊選項卡時,你會看到選項卡的導航控制器的根視圖

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
write your code here to move the ViewController as written below.(as your requirement) 

[navcontrol1 popToRootViewControllerAnimated:YES]; 
[navcontrol2 popToRootViewControllerAnimated:YES]; 
[navcontrol3 popToRootViewControllerAnimated:YES]; 

} 
0

創建三個視圖控制器,然後將每個視圖控件賦予每個單獨的navigationcontrollers。然後將三個導航控制器分配給TabBar。

self.tabBarController = [[UITabBarController alloc] init]; 
    [self.tabBarController setDelegate:self]; 
    self.tabBarController.viewControllers = @[navigationController1, navigationController2,navigationController3]; 

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
    { 
     write your code here to move the view 
    } 
2

創建三個視圖控制器(您需要五個),然後將每個視圖控件賦予每個單獨的navigationcontrollers。然後按如下方式將三個導航控制器分配給Tabbar:

RideViewController* rideObj = [[RideViewController alloc]initWithNibName:@"RideViewController" bundle:nil]; 
RequestARideViewController* requestARideObj = [[RequestARideViewController alloc]initWithNibName:@"RequestARideViewController" bundle:nil]; 
MyAccountViewController* myAccntObj = [[MyAccountViewController alloc]initWithNibName:@"MyAccountViewController" bundle:nil]; 


navCtrlObj1 = [[UINavigationController alloc]initWithRootViewController:rideObj]; 
navCtrlObj2 = [[UINavigationController alloc]initWithRootViewController:requestARideObj]; 
navCtrlObj3 = [[UINavigationController alloc]initWithRootViewController:myAccntObj] 

self._tabBarController = [[UITabBarController alloc]init]; 
self._tabBarController.delegate=self; 
self._tabBarController.viewControllers = [NSArray arrayWithObjects:navCtrlObj1,navCtrlObj2,navCtrlObj3,nil]; 

-(void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController 
{ 
    write your code here to move the ViewController as written below.(as your requirement) 


      [navCtrlObj1 popToRootViewControllerAnimated:YES]; 

      [navCtrlObj2 popToRootViewControllerAnimated:YES]; 

      [navCtrlObj3 popToRootViewControllerAnimated:YES]; 



} 
相關問題