UINavigationController.navigationBar setHidden:NO doesn't work? - ios

I have a HomeViewController and it has a property searchViewController.
HomeViewController is the delegate of searchViewControllerDelegate so that I can pop searchViewController when I click a button in searchViewController.view (I use pushViewControllerAnimated: to push searchViewController into view controller stack.
I want to show the navigationBar when the searchViewController is popped up.
However
[self.navigationController.navigationBar setHidden:NO];
is definitely not working.
I've checked that the navigationBar is not nil so I can't figure out what the problem might be.
actual code
#pragma mark - HomeTabSearchTableViewDelegate
-(void)parentViewControllerPop{
[self.navigationController popViewControllerAnimated:YES];
[self.navigationController.navigationBar setHidden:NO];
}
searchViewController is popped up successfully, just the navigationBar problem.

on your HomeViewController
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO]; //shows
//or use like
// [[self navigationController] setNavigationBarHidden:NO animated:YES];
}
-(void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES]; // hides
//or use like
// [[self navigationController] setNavigationBarHidden:YES animated:YES];
}

Related

how to hide navigation controller number 1 instead navigation controller number 2 inside navigation controller number 1

2 Controllers
PageviewController
1)
- (void)applicationDidFinishLaunching:(UIApplication *)application
[self.window setRootViewController:navigationController];
On bottom toolbar button click in view pushing second UINavigationController:
[self.navigationController pushViewController:cnController animated:YES];
Loading of UIPageViewController in UINNavigationController:
#interface SwipeBetweenViewControllers : UINavigationController <UIPageViewControllerDelegate,UIPageViewControllerDataSource,UIScrollViewDelegate>
On bottom toolbar button click in view:
SampleViewController *viewController = [[SampleViewController alloc] initWithStyle:UITableViewStyleGrouped];
viewController.model = settingsModel;
viewController.navigationItem.title = #"Settings";
[viewController willMoveToParentViewController:self];
// [[self navigationController] setNavigationBarHidden:YES animated:YES];
[self.view addSubview:viewController.view];
[self addChildViewController: viewController];
[viewController didMoveToParentViewController:self];
[self.navigationController pushViewController:viewController animated:YES];
It shows 2 navigation controllers. I need to hide the top one when I issue following:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
It hides UIPageviewcontroller navigation and go back to original view. I also tried:
NSMutableArray *allControllers = [self.navigationController.viewControllers mutableCopy];
[allControllers removeObjectAtIndex:allControllers.count -1];
and also
for (UIViewController *controller in self.navigationController.viewControllers)
{
if ([controller isKindOfClass:[SampleViewController class]])
{
[[self navigationController] setNavigationBarHidden:YES animated:YES];
}
}
How to hide specific original navigation controller?
Thanks for all your help.
I was able to solve this.
Actually, I was pushing viewController to top one #1 navigationcontroller, whereas it was to pushed into bottom one #2 navigationcontroller.
And wrapping #2 navigationcontroller in a containerUIviewcontroller set right navigation.
Thanks

jump between the ViewControllers which the navigation bar is hidden

I have a problem about the navigation bar.
I have ViewControllerA with a hidden NavigationBar. I have set the navigationBar hidden using the code below:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
-(void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
I push ViewControllerA and then ViewControllerA again. But NavigationBar will appear when I go back to First ViewControllerA by using system gesture.
I hope I can get some ways to solve this problem. Thanks.
You're almost there, hide it in ViewControllerA and then show it in ViewControllerB, don't show it when ViewControllerA will disappear. The below code is all you need, good luck.
ViewControllerA:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:animated];
}
ViewControllerB:
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
}
Dear First You are set Navigation bar hidden at Navigation Controller Property (Storyboard->Click Navigation Controller->Property) and You want Navigation Bar in any View Controller Scene so your are add this code in .m file of view controller.
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}

iOS - NavigationBar hide/show

I have a master viewController and many detail viewController. Master viewController doesn't have any UINavigationBar but detail viewController has UINavigationBar. So I have some problem. When I swipe from detailVC to masterVC UINavigationBar hiding in detailVC
Have you any solution this?
I use these methods (master viewController )
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
(detail viewController)
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
Finally
I have solved this issue.
I wrote UINavigationBar hiding code for firstVC in the viewDidAppear method.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}

PresentViewController hides Navigation bar in iOS

I am trying to show navigation controller when i present PresentViewController for navigate a screen. I solved this problem, but i faced another problem. Problem is when i push to a screen that time back button is visible on next screen with navigation controller. But when i am trying to PresentViewController, that time navigation bar is visible but not back button.
Here is my code:
- (IBAction)clickMeAction:(id)sender
{
ViewController1 *viewcontrol = [self.storyboard instantiateViewControllerWithIdentifier:#"ViewID"];
//[self.navigationController pushViewController:viewcontrol animated:YES]; // this is for push to viewcontroller
UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:viewcontrol];
[self presentViewController:navigationController animated:YES completion:nil]; // This is for modalviewcontroller
}
Here is my output:
with push:
with modal:
Please help me.
Method 1:
[navigationController presentViewController:navigationController animated:YES completion:^{
[navigationController setNavigationBarHidden:YES animated:NO];
}];
Method 2: in presentViewController
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}

NavigationBar Hidding issue on Back

On View1 I hide the navigationBar in viewDidLoad:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:YES];
}
Then I navigate to View2 where I show the navigationBar
- (void)viewDidLoad
{
[super viewDidLoad];
[self.navigationController setNavigationBarHidden:NO];
self.title = #"Title";
}
But on back to View1 again, the navigationBar doesn't hide, even if I did tried to hide it after the pushViewController in View2
[self.navigationController pushViewController:View1 animated:YES];
[self.navigationController setNavigationBarHidden:YES];
I also tried to hide the navigation from viewWillAppear in View1 and it hides it, but there is an ugly delay and I don't find it as a good practice.
So can anyone help me with this issue, how can I hide correctly the navigationBar on back to View1?
The best practice to do what you want is putting bellow in your first viewController:
- (void)viewWillAppear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:YES animated:animated];
[super viewWillAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
[self.navigationController setNavigationBarHidden:NO animated:animated];
[super viewWillDisappear:animated];
}
-(void) viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}
The ViewController1 is not going to get allocated again and so viewDidLoad is not going to get called.
You can do it in viewWillAppear though. But if you are saying that there is a delay, you can do one more thing.
You can get the reference ofViewController1 in ViewController2. Suppose ViewController1 is the first controller in the navigation controller, then do this:
//ViewController2.m
- (IBAction)backButtonPressed:(id)sender{
ViewController1 *view1 = [self.navigationController.viewControllers objectAtIndex:0];
[view1.navigationController setNavigationBarHidden:YES];
Your code is correct, but you need to write like this:
[self.navigationController setNavigationBarHidden:YES];
first, then write
[self.navigationController pushViewController:View1 animated:YES];
See when you are pushing View2 from View2 in navigation stack than View1 doesn't gets deallocated. it is there in in the stack. So when you popping out View2 that time View1 viewDidLoad won't get called. so your code setNavigationBarHidden to hide navigation bar doesn't executes. So put that code to ViewWillAppear or ViewDidAppear because these methods gets called every time View appears.
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
}

Resources