85336

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

  • iOS application crashes after AppStore publication
  • Subsequent NSURLConnections not firing delegate methods
  • Is there an Cocoa or Objective C api for Java?
  • Is there an Cocoa or Objective C api for Java?
  • UITabbarController dismiss modal UINavigationController
  • iOS: define and use C++ in Objective-C++
  • Objective-C Thread 1:Program received signal: “SIGABRT”
  • How to check if the screen hasn't been clicked in Android?
  • UIVisualEffectView creates a grey box instead of blurring
  • 'Terminating app due to uncaught exception'.. it couldn't find MainWindow, which no l
  • Merge two imageViews into one and save iOS swift
  • wxPython: How to get sizer from wx.StaticText?
  • How to Update UILabel from Another ViewController
  • Android Media player seekbar play from stopped position
  • Load image without autoscaling in Android
  • How do I recognize a line break with a switch case that evaluates a char in Java?
  • How to add System.Windows dll to Visual Studio 2010 express?
  • I have two activity.I want to Send the data from second activity to previous activity.First activity
  • Why doesn't a local variable live long enough for thread::scoped?
  • Is there any way to call saveCurrentTurnWithMatchData without sending a push notification?
  • Angular Bootstrap Carousel Slide Transition not working correctly
  • Outlines on links in IE9 remains when focus is changed
  • How can I restyle a word when rendering a pdf with pdf.js?
  • Image map in Flex
  • Who propagate bugfixes across branches (corporate development)?
  • Silverlight DependencyProperty.SetCurrentValue Equivalent
  • MySQL Order by column = x, column asc?
  • Change multiple background-images with jQuery
  • Read text file and split every line in MSBuild
  • Align navbar back button on right side
  • Can Jackson SerializationFeature be overridden per field or class?
  • Window Size for Mac application
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • NSLayoutConstraint that would pin a view to the bottom edge of a superview
  • Is there any way to bind data to data.frame by some index?
  • Django query for large number of relationships
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • How can I use `wmic` in a Windows PE script?
  • How to push additional view controllers onto NavigationController but keep the TabBar?