Navigation controller with tab bar controller of navigation controller - ios

I have a navigation controller, and its root view controller is a tab bar controller. In this tab bar controller I have two view controllers like this:
In the tab bar controller I have a custom navigation bar.
When I click the first item in tab bar, the navigation bar looks good
but when I click the second, I have a problem: below the navigation bar there is another navigation bar with red color.
Can some explain this for me?

If you don't want navigation bar of first navigation controller then from the interface builder (storyboard) select your root navigation controller (i.e. navigationcontroller that's embed with tabbarcontroller) and from attribute inspector uncheck shows navigation bar under Navigation controller! This will hide navigation bar for root navigation view controller!!
In your case you should hide and show navigation bar in viewWillDisAppear and viewWillAppear something like,
In viewWillAppear
self.navigationController.navigationBar.hidden = NO;
In viewWillDisAppear
self.navigationController.navigationBar.hidden = YES;
Do above things for your both viewcontroller of your tabbarcontroller!!

You can do navigationController.navigationBarHidden = true on the root navigation controller, or the child whatever suits you.
But the better will be if you use only one UINavigationController, and IMO navigationController of UITabBarController only.

Related

Status bar won't hide if view controller is presented

I have multiple storyboards in my project. I have a home page view controller in one storyboard, and I have a Setup view controller embedded in a navigation controller in a separate storyboard. Now when I Present the setup view controller navigation controller from the homepage view controller, the status bar won't hide. But when I set the setup view controllers storyboard as the main storyboard file base in the info.plist and the setup view controller navigation controller is the first view presented then the status bar will hide. I'm using the code below to hide the status bar. Can someone show me how to hide the status bar when the status view controller is presented by another storyboard view controller instead of being set as the first view controller. Here is the code I'm using to hide the status bar,
override var prefersStatusBarHidden: Bool {
return true
}
You can hide status bar in a condition.. You need to add another Window Object over the status bar.
let stautsBarWindow = UIWindow(frame: UIScreen.main.bounds)
stautsBarWindow.backgroundColor = UIColor.clear
//Instead of Presenting just assign your viewController in below line it will hide your statusBar as well.
stautsBarWindow.rootViewController = yourSideMenuViewController
stautsBarWindow.windowLevel = UIWindowLevelStatusBar
stautsBarWindow.isHidden = false

In Swift, I have 2 navigation bars but want to hide one of them, how to do it?

I currently have a viewcontroller that has two navigation bars because Its has a navigation controller both before and after a tab bar controller. I tried to have it so that the viewcontroller before the tab bar controller will present modally but by dong so the 2nd nav bar didn't work properly. The 2nd nav bar is a custom side menu that only appears to work if the first navigation controller is preset. Here is a pic
Is there a way so that only the bottom nav controller is visible?
If I understand your question correctly, you want to hide the ui for the enclosing navigation controller - i.e. the nav bar. You can do that by setting it hidden in the viewDidLoad() function of that view controller:
override func viewDidLoad() {
super.viewDidLoad()
navigationController?.setNavigationBarHidden(true, animated: false)
}

View under translucent navigation bar?

How can I make the view of a view controller extend to be full screen, meaning that it even resides under a translucent navigation bar?
You can place your view controller under the navigation bar.
if ([viewController respondsToSelector:#selector(setEdgesForExtendedLayout:)]) {
[viewController setEdgesForExtendedLayout:UIRectEdgeAll];
}

How to set the navigation bar title from view controllers inside tabs?

I have a tab bar controller embedded in a navigation controller.
I want to set the title in the navigation from the view controllers inside the tabs.
If I use:
self.title = "ABC";
or
self.tabBarItem.title = "ABC";
the title of the tab at the bottom is set to "ABC", but not the title in the navigation bar at the top.
However, I only want to set the title in the navigation bar, not the tabs at the bottom.
How can I do that?
You can set it using self.navigationItem.title.
self.navigationItem.title=#"ABC";
You have to pass the navigationItem up the chain.
The UINavigationController shows the navigationItem belonging to its topViewController which is UITabBarController.
The UITabBarController shows the navigationItem titles in its tabs. So what you need to do is make sure that the tabBarController's navigationItem is it's selectedViewController's navigationItem
So to recap:
UINavigationController title = topViewController.navigationItem.title
UITabBarController tabTitle = selectedViewController.navigationItem.title
UIViewController title = navigationItem.title
You are probably using the wrong element, try with the following example :
self.tabBarController.title = #"YOUR_TITLE";

alternating between toolbar / tab bar

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?
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.
Try to assigning toolbar with appropriate frame and adding it to self.tabBarController.view

Resources