Remove navigation bar from main controller in Xcode? - ios

I have a main view controller in Xcode 6 (program is in swift) on which I have a few buttons that lead to certain navigation controllers. When I test the app, the first time I see it it looks fine (without a navigation bar at the top). When I click on a button on main view controller, it shows the navigation controller I selected, everything acts perfectly again. The problem happens when I click on the bar button "back" on that nav controller in order for it to show me my main view controller again. When I'm back to the main view controller, there's a navigation bar at the top that isn't supposed to be there. I want my main view controller to have no navigation bar at the top. I tried to use push, modal and show segues to see if it might be the problem, but I still can't figure it out. Any thoughts on what might be happening?

Sounds like you need to re-hide your navigation bar. To do that, add:
self.navigationController?.navigationBarHidden = true
to the viewWillAppear of whatever view controller for which you'd like to hide the nav bar.
Updated for Swift 3:
self.navigationController?.isNavigationBarHidden = true

In mainViewController, write code to hide navigation bar in viewWillAppear method.
in Objective-C
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
[[self navigationController] setNavigationBarHidden:YES animated:NO];
}

Related

Unable to configure UINavigationBar for view embedded in Tab Bar Controller

I a writing an app (iOS8) that ultimately needs to load a UITabBarController via a segue from a UITableView. For the most part this setup can be done via Storyboards and works as expected, however I would also like to add a UIButtonBarItem to the destination view which is where the problems start.
A setup that works (without a UITabBarController) can be configured as follows
The button uses a "Show" segue to display the final view controller
The second UIBarButtonItems are added by copying over the Navigation Item from the first view controller (How to add buttons to navigation controller visible after segueing?)
If I run this in the Simulator, everything works as expected and I see both the back button and the desired "Add" UIBarButtonItem:
If I then embed the final view controller in a UITabBarController, the UIBarButtonItem I added disappears and so far any changes I have made to the storyboard setup (adding a UINavigationController in between the UITabBarContoller and the last view for example) or attempts to add the UIBarButtonItem programatically don't make a difference:
Is there anyway to get the final setup working with both a UITabBarController and UIBarButtonItems?
I have the same setup in one of my apps and it works fine. Not sure why you are having issues, but I did add a few lines of code in my custom Tab Controller that may help you. I think the issue is that the nav bar from the original navigation controller is still being shown, so subclass UITabBarController and put these lines in viewWillAppear:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationItem setHidesBackButton:YES];
[self.navigationController setNavigationBarHidden:YES];
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
In my app, the views before the tab bar controller were login/register views, so there was no reason to navigate back to them after entering the tab controller "stack," but I'm sure it won't be difficult to add a back button that accomplishes this. I believe you only need the [self.navigationController setNavigationBarHidden:YES]; line, which only hides the nav bar instead of hiding the back button or disallowing the pop gesture.
I know this is late but I just want to add swift 3 code.
The reason being that the NavigationBarA of the tabBarController is hiding your NavigationBarB that sits in between your tabBarController and the final ViewController. So you just have to set to hide the NavigationBarA
in viewWillAppear of your final ViewController you can add the following (without a need to subclass tabBarController)
self.tabBarController?.navigationController?.setNavigationBarHidden(true, animated: false)

UIBarButton unclickable in empty ViewControllers

i've created a tabBarController subclass and linked 3 viewcontrollers to the TabBarController in the storyboard. In the 3 ViewControllers which is directly connected with the tabBarController the UIBarButtons wont react when i click. They wont show the log message and does not do the highlight color. It seems like the navigationBar interaction is disabled or something. When i present a view modally on top of one of the 3 ViewControllers i have no problem with interaction with a UIBarButton in the modally presented View. I'm wondering what could result in such? i've struggled with this for ours.
i don't know if this has anything to do with it aswell, but in the modally presented views this does also result in white statusBar textColor, but it does not change it in the 3 views connected to the TabBarController.
What could this issue be?
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
self.navigationController.navigationBar.translucent = NO;
i've simply manually added a UIBarButton in the storyboard and then connected this action.
-(IBAction)testAction :(id)sender {
NSLog(#"test");
}
Try this
You just take 3 Navigation Controller as your tab bar view controller rather than simply view controller.
And connect tab bar view controller with navigation controller.
On navigation controller there is one view controller, on that navigation bar put your bar button item and connect to IBAction Method.
Its works for me.

hide navigation bar throughout the app

I know using below statement I can hide navigation bar.
[self.navigationController setNavigationBarHidden:YES animated:NO];
But I want to do this for whole app.
I don't want to write this statement in all files.
So any idea how can I hide navigation bar for whole project?
If you have used Storyboards, then setting the Navigation Bar to None in the Navigation Controller, and ensuring that the top bar is set to 'Inferred' for all view controllers contained within the navigation controller will ensure that the navigation bar will be hidden for all view controllers in the navigation controller.
You can also use
self.navController.navigationBar.hidden = YES;

Modal Segue Into Navigation Controller with No Nav Bar

In my storyboard I have a view with a segue into a new view that's embedded into a Navigation Controller (so the segue points to the navigation controller). I have the segue set to a Modal transition, however when the new view is animating up, it contains the standard blue navigation bar above the view (which then animates out of view).
Here's what it looks like mid segue: http://i.imgur.com/3eqAQ.png
How do I make it so the modal view animates up but without the navigation bar?
I have tried hiding the navigation bar in the embedded view's init, viewWillAppear, and vieWillLoad methods and that doesn't work.
I event went so far as to create a custom subclass of UINavigationController and set the navigation controller in the storyboard to it.
Thanks!
This may sound pretty simple, but have you tried hiding the navigation bar immediately before the modal segue starts? I had this problem when presenting a modal view controller and adding a [self.navigationController setNavigationBarHidden:YES] immediately before the presentation did the trick for me.
I had almost the same problem, but I wanted to get a navigation bar for my modal transition, as it was always hidden.
There may be two ways for you to remove the navigation bar:
Make sure that your view controller is not embed in a navigation controller, as it would put one by default
Check the "Top Bar" attribute of your previous controller in the workflow and work with none/inferred values depending on your storyboard.
Regards

Problem with "Presenting a controller modally within a nav controller within a tab bar controller"

My app has two distincts modes. There's a tab bar controller in the app delegate. There are two tabs, both using subclassed view controllers. The two view controllers essentially contain a nav controller each. The nav controllers have their root view controller, and normally when changing screens, I just push and pop controllers of the respective nav controller. This has the (normal) effect that the bottom tab bar is always visible, all great and sound.
This one time I'd like to present a screen modally however, so that the user can't do anything else than confirm or cancel the page using two buttons, ie I want to hide also the bottom tab bar. This would be a case for presenting the view modally I thought, but the view is presented within the nav controller bounds it seems, so the bottom tab bar is still visible, and this causes confusion in navigation the app. I'm not sure how it's possible that the modally presented view is not hiding the tab bar. Most of the questions around here seem to have the problem the other way around (wanting to (incorrectly) present a modal view and leave the tab bar visible).
These are my attempts:
[self presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
[self.tabBarController presentModalViewController:controller animated:YES]; // nothing is displayed. The new controller is instantly deallocated.
[self.navigationController presentModalViewController:controller animated:YES]; // inside tab bar controller :-(
Investigating this, the self.tabBarController is actually nil. There seems to be no link back to the tab bar controller... I guess, to display modally on top of the tab bar, I need to get a link to that tab bar controller?
I seem to have found a solution, I'm not sure it's kosher, because somehow I wasn't able to use the self.tabBarController pointer of the view controller in which I start the view controller call.
What I did was reach for the app delegate, the app delegate having the tab bar controller defined as a public property. I could use that tab bar controller property to modally display my view controller over everything on the screen.

Resources