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

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?

Answer1:

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.

Answer2:

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

人吐槽 人点赞

Recommend

Comment

用户名: 密码:
验证码: 匿名发表

你可以使用这些语言

查看评论:How to push additional view controllers onto NavigationController but keep the TabBar?