Kyle Roach
Kyle Roach

Reputation: 656

Presenting Navigation Controller within Tab Bar Controller

My application has a tab bar controller with two controllers embed - a navigation bar and a view controller.

We'll call the View Controller Number Pad and the Navigation bar and its root view controller Display.

I have a button in Number Pad that takes in input from a textfield and displays the corresponding information in a label on Display.

This is my code for the button:

SongController *songMain = [self.storyboard instantiateViewControllerWithIdentifier:@"SongDisplay"];

UINavigationController *navigate = [[UINavigationController alloc]initWithRootViewController:songMain];

[self presentViewController:navigate animated:YES completion:nil];

When I used this method the tabBar on Display is missing. Is there anyway to still have both the tab bar and Navigation Controller at once?

Upvotes: 0

Views: 325

Answers (1)

rdelmar
rdelmar

Reputation: 104082

The way you're trying to do this is wrong. The navigation controller already exists (as one of the tab bar controller's view controllers) so you don't want to instantiate it again, or present it. What you want to do is change the selectedIndex parameter of the tab view controller to switch to that view:

self.tabBarController.selectedIndex = 0;

Upvotes: 1

Related Questions