alternating between toolbar / tab bar
Asked Answered
R

2

8

my app is structured as follow: UITabBarController > UINavigationController > ViewControllerOne > ViewControllerTwo. the UINavigationBar has at the bottom the tab bar, now when the user navigates into the second view controller, i want to be able to hide the tab bar and replace is with a tool bar. i tried this code:

[self.navigationController.tabBarController.tabBar setHidden:YES];
[self.navigationController.toolbar setHidden:NO];

when i run the app the tab bar is hidden but the toolbar doesn't appear. plus, since the last VC is a table view controller, when i scroll through the cells there is a white gap between the table and the bottom of the view. how can i fix that?

Replicate answered 28/11, 2013 at 12:5 Comment(3)
Where do you call this method? Is it viewDidAppear:? if not try to move it there.Fluency
@Fluency i didn't put is there and i tried this but it didn't work. i enabled the toolbar from the inspector on the second view controller and added an item (also connected it to my class). but it's not working. nothing showing and there is still a white gap. thanks for the input.Replicate
@Fluency okay in the inspector under simulated metrics, i checked "show toolbar" now it's showing however the tab bar and tool bar are over each toher. i'm gonna find a way to fix that.Replicate
G
11

That won't work because when you hide the tab bar like that the subviews won't be adjusted properly (that's why you get the white space). You'll have to use

self.hidesBottomBarWhenPushed = YES;

In your init method or awakeFromNib... and then

[self.navigationController setToolbarHidden:NO animated:YES];

In the viewDidLoad for example.

That way the tab bar controller's view is going to layout correctly it's subviews when you hide the tab bar. Just remember to call self.hidesBottomBarWhenPushed = NO; in your first view controller otherwise the tab bar is still going to be hidden when the second view controller is popped from the navigation stack.

Geomorphology answered 28/11, 2013 at 14:44 Comment(2)
thanks for the input! it did work! however, i placed it in the the source view controller and not the destination view controller. i placed it in the prepareForSegue: not in the init.Replicate
I was confused on whether to call hidesBottomBarWhenPushed in first VC or second VC. Finally called in awakeFromNib for second VC and it worked like a charm. (Did not work when added to ViewDidLoad)Detonate
I
0

Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

Insert answered 28/11, 2013 at 12:31 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.