I am working with UITabbarController and UINavigationController for my application. And i have created application with UITabbar base application it that i am giving different type of navigation controller to navigate view. As given below image. enter image description here

But i have 1 problem which i describe as follows:

Suppose i have 5 ViewController and 3 NavigationViewController for that all five view controllers like View1 as rootViewController and view2 as subview. view 3 as RootViewController for 2nd NavigationViewController and view 4 as subview of 3rd RootViewController and others.

When i run application at that time view1 loaded as RootViewController now i am navigation to view 2 as it's subView of view 1 at that time my tab bar selected to first tab. When i click on 2nd tab bar button it shows me view 3 as RootViewController for 2nd NavigationController.

And now i am clicking back to 1st Tabbar button to view view 1 but it shows me subview view 2. If i need to move to RootViewController i need to press back button to View my RootView.

So according to my sinario is it possible to set RootView for that particular tab bar so user can easily go to RootView without viewing subviews for all tab bar click items.

Please help me.

有帮助吗?

解决方案 2

use this code. When ever you are clicking the tab you be shown the root view of the navigationcontroller of the tab

 -(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];

}

其他提示

Create the three view controllers(You five as your requirement), and then give each view control to the each separate navigationcontrollers. and then assign three navigationcontrollers to the tabbar as follows-

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];



}

Create the three view controllers, and then give each view control to the each separate navigationcontrollers. and then assign three navigationcontrollers to the 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 
    }
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top