How to push additional view controllers onto NavigationController but keep the TabBar?

纵然是瞬间 提交于 2019-12-24 04:44:27

问题


I have an app that starts with a basic view controller at the root of my navigation controller

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.navController.viewControllers = [NSArray arrayWithObject:[self getHomeViewController]];

    [[self getWindow] addSubview:self.navController.view];
    [[self getWindow] makeKeyAndVisible];

    return YES;
}

Once a navigation item is selected I push a tab bar controller w/ a few view controllers.

-(void)launchOptionWithTabBarController:(NSUInteger)selectedIndex
{
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:
                                             [self getFirstViewController], 
                                             [self getSecondViewController],
                                             nil];

    [self.tabBarController setSelectedIndex:selectedIndex];
    [self.navController pushViewController:self.tabBarController animated:YES];
}

The problem is that I now need to add another view controller on top of the one open in the tab bar controller ... and when I push one to the navigation controller like so ..

- (void)launchNewViewControllerWithArray:(NSArray *)stuff
{
    self.newViewController = [self getNewViewController];

    [self.navController pushViewController:self.newViewController animated:YES];
}

I no longer see the tab bar navigation (and I would prefer to see this nav w/ each item I push).

How can I modify my control flow so the tab bar nav items stay along the bottom?


回答1:


You need to parent the navigation controller in the tabbar controller instead of vice versa. Or introduce another navigation controller parented on your tabbar controller, and push the new viewcontroller onto that.




回答2:


You can achieve this by pushing new viewController on tabbar selected viewcontroller. so you can write your launch function like this

- (void)launchNewViewControllerWithArray:(NSArray *)stuff
{
    self.newViewController = [self getNewViewController];

    [[self.tabbarController selectedViewController] pushViewController:self.newViewController animated:YES];
}


来源:https://stackoverflow.com/questions/9936114/how-to-push-additional-view-controllers-onto-navigationcontroller-but-keep-the-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!