开发者

Hiding the tab bar when view is pushed

long time reader, first time asker-er?

So basically I have a tab bar application with a navigation controller for each tab (they each go down several levels of views) I'm currently hiding the tab bar when I need to using this code:

MyViewController *myVC = [[MyViewController alloc]initWithNibName:@"MyViewController" bundle:nil];

myVC.hidesBottomBarWhenPushed = YES;

[self.navigationController pushV开发者_StackOverflowiewController:myVC animated:YES];

[myVC release];

This works fine, however in one of my tabs I haven't created the navigation controller in IB but instead, programatically

Here is the code for creating the navigation controller programatically:

UINavigationController * navigationController = [[[UINavigationController alloc] init] autorelease];

self.segmentsController = [[SegmentsController alloc] initWithNavigationController:navigationController viewControllers:viewControllers];

self.segmentedControl = [[UISegmentedControl alloc] initWithItems:[viewControllers arrayByPerformingSelector:@selector(title)]];
    self.segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar;

[self.segmentedControl addTarget:self.segmentsController
                              action:@selector(indexDidChangeForSegmentedControl:)
                    forControlEvents:UIControlEventValueChanged];

[self.view addSubview:navigationController.view];

What I am creating here is a nav bar with a segmented control within, that pushes views, within one of the segmented control views (it's a list) when I click on a list item I want to hide the tab bar, but nothing happens using the code at the beginning of this question, I'm assuming it's something to do with how the navigation controller was made, the views push and pop just fine but that TabBar stays visible when I want to hide it, does anyone have any idea as to how I can hide this tab bar?

Thanks for any feedback in advance!

Edit: As a 'new user' I can't submit a picture to help visualise the problem, figures. Oh well hopefully what's going on here isn't too fuzzy for you guys.


It's hard to get exactly what you're trying to achieve with the code you've given (and without the screen shot!), but it looks like the problem may be that you're just adding the nav controller's view directly as a subview, rather than adding the nav controller to the view controller hierarchy.

So, rather than

[self.view addSubview:navigationController.view];

use

[self.navigationController pushViewController: navigationController animated: NO];

This will of course mean that your view controller itself will have to be in a navigation controller stack (although you can always hide the nav bar so visually it will look the same)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜