views:

724

answers:

2

Hello,

I have created an UITabView application. Each view selected from the bar is a seperate controller with own nib file. I switch between them succesfully.

In the first view I have two buttons (check out the screenshot). When clicking them I want to switch to another views which are the parts of the current view controller. I use:

[self presentModalViewController:anotherViewController animated:NO];

That switches the view, but hides the UITabBar. How to keep the bar on the screen after the switch?

alt main alt after_click

P.S. Sorry for the blurred image. I am not allowed to share to much info.

+4  A: 

Well I think you are misusing the modal view controller. For a problem like this I'll say you should put them in a view controller stack using UINavigationController. Instead of making each tab a UIViewController make it a UINavigationController, then you can push and pop view controllers on it, which still show the tab bar.
See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html

phunehehe
Thanks. That is a great idea. However, I still have a problem with it. I have added UINavigationController instead of the UIViewController (see http://i50.tinypic.com/2rdd8g4.png ), put the UIViewController inside. It compiles, but theres a warning by [self.navigationController pushToViewController:anotherViewController animated:NO];, which is "UINavigationController may not respond to pushToViewController". And it crashes when I try using it ("unrecognized selector sent to instance"). I would be grateful for any hints.
Jacek
Oops, where did you find `pushToViewController:`? Did you mean `pushViewController:animated:`?Seehttp://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006934-CH3-SW2
phunehehe
+3  A: 

Hi,

use: tabBarController.selectedViewController = newViewController

edit: UINavigationController is not needed here.

Felix
if you know the index you can also use: tabBarController.selectedIndex = indexOfTabToView ;
Eld
If the navigation via the icons is purely hierarchical, amenable to the stack model of pushing to a new view and popping back to the previous, and not "circular" somehow then I'd probably still use the UINavigationController. You can tell it to hide the navigation bar and not use animation so it won't look like a navigation controller. (Circular would be like the system settings panel in OS X where one panel often has a button or something to jump to a different panel without popping back to the top level control panel view.)
Nimrod