views:

6586

answers:

5

I have an application with 5 UIViewControllers each inside a corresponding UINavigationController, all tucked inside a UITabBarController that displays 5 tabs at the bottom of the screen.

I want to display another UIViewController (inside a UINavigationController) when a dialog button is pressed.

This view should only be loaded and unloaded programatically; ie. it should not appear in the tab bar. However, I want the tab bar to be visible always.

If I add the [UINavigationController view] to [self window] the Tab Bar is covered. If I add it to any other layer, the Navigation Controller adds on the compensation it has for the status bar so appears further down than expected.

A solution would be to have the 6th Nav Controller added to the Tab Bar with the others, but with its tabBarItem hidden. Then I can show it and hide it using the tabBars selectedIndex property.

Accessing the tabBarItem through the View Controller shows no obvious way of doing this.

Anyone have any ideas?

Thanks!

+12  A: 
wisequark
+1  A: 

The best idea I could think of would be to either push a modal navigation controller for your view (which would hide the tab bar which you do not want), or to get the tab bar controller current selected view controller (really your navigation controller for a tab) and push your new view controller on there - and then pop that view when another tab is selected with a tab bar delegate.

It seems wierd to me to push the view onto random tabs though, if the view is created from a dialog that is modal, I don't see why the view itself should not also be modal and hide tabs.

Kendall Helmstetter Gelner
A: 

wisequark, I think you completely misunderstood and you have almost rewritten the architecture of my application.. however I have a seperate navigation controller for each view as they are mutually exclusive and there is no concept of "drilling down"

Kendall, this is what I expect I will have to do - have the modal view appear with a hide button to bring back the normal interface - but it would be nice to keep the tab bar always visible so I was just wondering if anyone knew of a way.

Thanks anyway!

adam
If there is no concept of drilling down then why are you using a navigation controller to manage views? It's sole intended purpose is for applications such as the iPod where one goes artist > album > song, etc.
wisequark
Of course this is not its "sole purpose" - You may have a far more complex navigation and using a navigation controller is the only way you can use navigation bar and navigation items correctly.
adam
+2  A: 

Well, it sounds like what you really want to do is present a modal view with the tab bar still visible. You could add your view as a subview of the tab bar controller's view. The tab bar's view is, oddly enough, not the tab bar itself but rather a view containing the tab bar and the selected item's view.

Alternatively, you could try calling presentModalViewController:animated: with the selected tab (i.e. [tabBarController.selectedViewController presentModalViewController:animated:]) as the receiver instead of the tab bar. I seem to recall doing this once (quite by accident) and the tab bar remained visible.

One more thought: since each of your five view controllers is a UINavigationController, you could always pushViewController:animated: onto the selected view controller, then hide the back button. Your view will just appear without animation. But you'll need to remember to pop your view controller off the stack whenever the user switches to another tab. That might take a bit more work.

Alex
+1  A: 

Here is a link from developer.apple.com where describe how to implement: