views:

37

answers:

1

A view is presented modally:

[self presentModalViewController:modalNavController animated:YES];

This view uses a UITabBarController with 4 elements. One of these elements, "Info" has a button that's only visible if its available. If the button is clicked, it needs to push to another view controller, but I'd also like to maintain the tab bar from it's parent view. I haven't been able to figure out how to do this with or without keeping the tab bar. Ive tried pushing and presentingModally in all the places that I could image. How should this be done properly?

Creating tab bar:

    infoController.title = @"Info";
    streetViewController.title = @"Street View";
    reviewController.title = @"Reviews";

    streetViewController.tabBarItem.image = [UIImage imageNamed:@"flag.png"];
    infoController.tabBarItem.image = [UIImage imageNamed:@"openMarker.png"];
    reviewController.tabBarItem.image = [UIImage imageNamed:@"reviews.png"];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
    tabBarController.view.frame = CGRectMake(0, 0, 320, 460);

    UINavigationController *infoNC = [[[UINavigationController alloc] initWithRootViewController:infoController] autorelease];
    infoNC.navigationBarHidden = YES;


[tabBarController setViewControllers:
    [NSArray arrayWithObjects:infoNC, streetViewController, reviewController, nil]];


[self.view addSubview:tabBarController.view];
+1  A: 

When you add the view controllers to the tab bar controller you need to do this:

MyCustomViewController *vc1 = [[MyCustomViewController alloc] initWithNibName:nil bundles:nil];
UINavigationController *nc1 = [[[UINavigationController alloc] initWithRootViewController:recipesRootView] autorelease];
[vc1 release];

then add nc1 instead of your custom view.

Then in MyCustomViewController to push another view controller do:

[self.navigationController pushViewController:(UIViewController *)page animated:YES];

That should work for you, and keep the tab bar controller.

Thomas Clayson
Thanks for the clear thinking, Thomas. The problem I'm getting now is that the "Back" button once the second view is open, closes the entire modal view hierarchy. I'll try replacing the back button with a different putton that pops the current view.
culov
can you post your whole code above please so I can see how you are making the tab bar controller and such. I don't know why that's happening, because it really shouldn't. :) you're not creating the tab bar controller **IN** a navigation controller are you?#
Thomas Clayson
I edit. Im adding the tab bar view as a subview.
culov
instead of `[self.view addSubview:tabBarController.view];` try `[self presentModalViewController:tabBarController animated:NO];` see if that works
Thomas Clayson
Well, the view onto which the tab bar is getting added, is already added modally. This DetailViewController just has a tab bar added to it, and the default view is the first item in the tab bar. the first item in the tab bar has the "menu view" button. Id like the menu button to push to a controller with the same bar as the modal view. I was thinking about doing this by recreating the modal view bar from the navigation bar and hiding the original modal view bar, but I havent discovered how to add the bar. I tried what you suggested and it just shows a black white screen w/ modal view bar
culov
I think you're making things too complicated - I don't really understand what you're trying to do. A tab bar controller is an overlay of an application. You shouldn't be making on in the middle of a navigation stack. Apple will most probably reject your application if thats what you're doing. If you want to show a tab bar controller on clicking a button you need to set the button action to `presentModalViewController:tabBarController ani...` and then the view you want to show needs to be the selected view controller in the tabBarController. You can't do it any other way i don't think.
Thomas Clayson
I created the tab bar the way it was done in this tutorial: http://www.iphonedevcentral.com/create-uitabbarcontroller/ I have a button in one of my views (not my RootViewController), which needs to present a modal view with a tab controller when tapped. I present the modal view and create the tab controller on load. One view in the tab bar controller is a UINavigationController so it can be pushed to the menu. In this view, I'd like to add a second back button (this one on the right, to return back to the main "Info" view in the tab controller.
culov
have you tried with `[self presentModalViewController:tabBarController animated:NO]`
Thomas Clayson
Yea, I didnt get that to work. The point you made about UITabBarControllers in the middle of the stack being prohibited led me to try a different solution. I spent all night re-writing the code and I ran into an obstacle at essnetially the same place. I implemented a UITabBar without a UITabBarController, but I still cant get the new modal view to display the nav bar I want! I posted a new question here: http://stackoverflow.com/questions/3765158/how-can-i-display-a-view-controller-modally-using-the-parents-navigation-contro
culov