Disabling navigation bar on segue when searching - ios

I've got an iOS app that's using a table view with a search bar added to the table view. When a row is tapped, I push another view controller that shows the details of the row that was tapped.
Our table view and detail view both hide the navigation bar.
When the search bar is not active, the navigation bar is disabled on the detail view controller, which is expected.
However, when search is active, the navigation bar shows up on the detail view controller. From what I've read, that's the default behavior for any transitions that occur when search is enabled. Is this accurate?
If so, is there anything I can do to hide the navigation bar? More generally, is there anything I can do to have the push of the detail controller behave the same way regardless of whether search is active or not?

This works
-(void)viewDidLayoutSubviews
{
self.navigationController.navigationBarHidden = YES;
self.navigationController.navigationBar.translucent = YES;
}

In your detail view controller try putting :
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
Link to doc

Related

Multiple segues remove navigation bar in view controller

I have a view controller that has a navigation bar. It is the root view controller of the navigation controller. I have another view controller that can be segued from a button on the first controller. Up to this point, everything works fine; there are navigation bars on both view controllers.
However, from the second view controller, I want to be able to segue back to the first controller. When doing this, it removes the navigation bar from both of the view controllers.
How can I get the navigation bar on both view controllers with buttons as transitions? Thanks!
Implement below method in your both viewcontroller,
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
You may hiding navigationbar somewhere.
Try this in storyboard:
Select the navigation controller -> Attributes Inspector -> Under Navigation controller and Bar Visibility leave the "Show navigation bar" blank

Navigation bar height changing on hide and unhide

In my application I have to show one screen with navigation bar and then by pushing another controller with no navigation bar.
When I come back I again want to show the navigation bar. But, my navigation bar is not visible with complete height.
I set the navigation bar with no translucent, and style opaque.
can you help me anyone.
this will hide and show navigation bar perfectly:
in first view controller implement:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
in pushed view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
Show some code...
or try showing the navigation bar from the view controller you're coming back from just before you tell it to go back... Should avoid the issue. But suspect you're doing something else wrong.
Use this method:
In view controller where you want to hide navigation bar add the below code in viewWillAppear
[navigationController setNavigationBarHidden:YES];
So, if you are in some view controller:
In view controller where you want to show navigation bar add the below code in viewWillAppear
[self.navigationController setNavigationBarHidden:NO];

Wired black space under screen when pop to previous view controller using UINavigationController

I am using UINavigationController to direct some view controllers.In some view controller, I don't want to use UINavigationBar, but in some others i may use. Now I am try to pop one view controller using UINavigationBar to its previous one which hide UINavigationBar. But when poped, there is one wired black space under screen. After you rotate the screen, the space will disappear.
the normal view controller A should be like this:
when press the text button, a view controller B will be pushed, which is as followings:
when click back button on the navigation bar. A will come out.but there is a black space at the bottom.
If rotate the screen, the space will disappear. And also in A's - (void)viewWillAppear:(BOOL)animated method i hide the navigationbar and let the screen autorotate.
- (void)viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
[self willAnimateRotationToInterfaceOrientation:[UIApplication sharedApplication].statusBarOrientation duration:0];
}
whats wrong with this situation? Any help will be appreciated.
I add setNavigationBarHidden: method in the back button action method. it works. If i add this method in viewWillDisappear: method or others, it seems it doesn't work. The navigation bar will have effect on next appear view controller. which means, there will be a black space in the next view controller in the navigation stack.
Finally, i add a action method for the back button and setNavigationBarHidden:YES in the method, which is as follows:
- (void)backBtnClicked:(id)sender
{
[self.navigationController popViewControllerAnimated:NO];
[self.navigationController setNavigationBarHidden:YES];
}

I have view controllers in a navigation controller hierarchy, but only want the navigation bar on the first view controller - how do I do this?

I have a main view controller that lists a bunch of items, and when they tap on one of the items it segues them to the next view. However, in the next view, I don't want the navigation bar to be there, I only want it in the first view (I'm using a UIToolBar for the navigation bar, kind of like in iBooks).
How exactly do I go about achieving this? If I remove the main view controller from the navigation controller completely (unembedding, effectively) I can implement the nav bars selectively, but this solution doesn't allow segues, so it's no good.
My other solution was to call self.navigationController.navigationBarHidden = YES; in viewDidAppear for the second view, but with this, the UIToolBar that I added in my storyboard is pushed under the navigation bar that hasn't been hidden yet, and then when it does get hidden, it disappears and the UIToolBar "falls down", which is a pretty gross effect to the user.
What would be the best way to go about getting this effect?
The best way to do that is the following. In you viewWillAppear: in the first (rootViewController) of your UINavigationController, you set:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
and then in you viewWillDisappear, you the the opposite:
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
This way should work without nothing 'ugly' happening to the user.

Set navigation bar hidden, depending on how the view controller appeared

I have a tab bar with a navigation controller in one of the tabs. Currently the root view of the navigation controller doesnt have the nav bar showing and animates nicely into the subviews by
- (void)viewDidLoad {
...
[self.navigationController setNavigationBarHidden:YES animated:NO];
...
}
and
- (void)viewWillAppear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
But of course changing tabs initiates the viewWillAppear function and so as I go back to the root view the navigation bar slides away, rather than just not being there.
Is there a way that I can hide the nav bar on the root view without animating it except for when appearing from a subview on the navigation stack?
The (BOOL)animated parameter on viewWillAppear:animated. When changing Tabs, it will come as NO, since the animation is immediate. On the other hand, if it's being pushed or popped from the navigation stack with animated:YES, then it will come as YES.
Although this looks like a hack, it's the correct way: you don't need to figure out who was the caller, instead, focus on the fact that if your view controller will appear animated, you have time to do your own animations, if not, screw it, show (or in this case, hide) everything immediately.
Try showing/hiding the bar in the UINavigationController's delegate's navigationController:willShowViewController:animated: method, depending on whether the view controller being shown is your root view controller.
What if you set a boolean variable in your application delegate and in set that boolean accordingly in subviews as 0 and in other views as 1. And in your viewwillappear, according to your variable's value, you can set the animation.

Resources