Unable To show the navigation bar when I do popViewControllerAnimated - objective-c

I am having two viewControllers , I am navigating from the FirstView to SecondView , by
pushing the SecondView to the navigation controller. Since I don't want the navigation bar
to be shown in the SecondView , I do the following
self.navigationController.navigationBar.hidden=YES;
Then I move back from the, secondView to the FirstView as follows
[self.navigationController popViewControllerAnimated:YES];
But now the navigation Bar is not shown in the FirstView as well since I am hiding it in the
SecondView. I am trying to the following in the FirstView
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:YES];
self.navigationController.navigationBar.hidden=NO;
}

Try this instead:
- (void) viewWillAppear:(BOOL)animated
{
[self.navigationController setNavigationBarHidden:NO animated:NO];
[super viewWillAppear:animated];
}

You set initWithNib or viewDidLoad method and run it
-(void)viewDidLoad
{
self.navigationController.navigationBar.hidden=NO;
}

Trying show the navigationBar before you pop the second view controller, like this:
self.navigationController.navigationBar.hidden=NO;
[self.navigationController popViewControllerAnimated:YES];

try it in the following method:
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:YES];
self.navigationController.navigationBar.hidden=NO;
}
but to me it should work in viewWillAppear.

Place the below code in the second view
-(void)viewWillDisappear:(BOOL)animated{
self.navigationController.navigationBarHidden=NO;
}

Related

Navigation bar Hidden not working IOS

Hi I'm new in iOS development. I've one main screen with navigation bar hidden true. From there I am navigating to another view using back segue. but when I click back it showing navigation bar on main screen. Here is my problem description.
In main screen onviewload I am doing :
self.navigationController.navigationBarHidden = YES;
once user go to another view using back segue in new controller, I'm doing
self.navigationController.navigationBarHidden = NO;
And now, if I click back it will show navigation bar on main window also which I don't want. Basically I want main screen without navigation bar and next window with navigation bar.
How to do this. Need Help. Thank you.
Put that code in viewWillAppear instead of viewDidLoad, and it should work properly.
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
I have a Tab viewcontroller consist of 4 tabs, one of my tab doesn't need navigationbar, but others need.
None of the previous answers solve my case, these code does.
//隐藏App导航条,使用RN自己的导航条
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBar.hidden = YES;
// self.navigationController.navigationBarHidden = YES; //这句是 **完全没** 个卵用
// [self.navigationController setNavigationBarHidden:YES animated:NO];
}
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:NO];
}
//恢复App导航条
- (void)viewWillDisappear:(BOOL)animated{
[super viewWillDisappear:animated];
self.navigationController.navigationBar.hidden = NO;
// self.navigationController.navigationBarHidden = NO; //这句是 **完全没** 个卵用
[self.navigationController setNavigationBarHidden:NO animated:NO];
}
Don't use
self.navigationController.navigationBarHidden = YES;
You should use
self.navigationController.navigationBar.hidden = NO;
For Swift 4, add following in viewWillAppear
self.navigationController?.setNavigationBarHidden(false, animated: false)
self.navigationController?.setNavigationBarHidden(false, animated: false)
Put the above line of code in viewWillAppear instead of viewDidLoad.

UINavigationBar disappears iOS7

I have some wierd bug with UINavigationBar.
Sometimes it just disappears (actually if you move view to the half of screen, and then just release it)
Video example
In the first ViewController's viewWillAppear: method i call:
[self.navigationController setNavigationBarHidden:NO animated:YES];
The second ViewController's viewWillAppear: contains:
[self.navigationController setNavigationBarHidden:YES animated:NO];
I tried change animated: parameter, but it doesn't help.
Is it iOS7 bug or I just doing something wrong?
I found the reason for this.
That's happened because in info.plist
View controller-based status bar appearance is equal to YES
If change it to NO, then all will be fine
I got the same problem, and fixed it. the solution is:
Modify info.plist, set "View controller-based status bar appearance " to NO;
Delete all - (UIStatusBarStyle)preferredStatusBarStyle {} ;
If your view controller has different status bar style, use [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
e.g. in viewWillAppear set to light, in disappear ,set to dark style.
You should define appearance per navigation controller.
If you want to have a navigation bar on the second controller only you should do the following in that particular controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
That way it will event work if you would need to change order of your controllers.

Trigger events when switching views

It is easy.
Suppose I have two views: firstView and SecondView.
firstView is the ROOT view.
I load secondView from firstView:
secondView *secondViewController;
secondViewController = [[SecondView alloc]
initWithNibName:#"SecondView" bundle:nil];
[self.view addSubview:SecondViewController.view];
I added a "Back" button in secondView.
When I click that button I go back to firstView:
[self.view removeFromSuperView];
Here is the question:
When firstView -> secondView, viewDidLoad in secondView is triggered.
How can I trigger an event to inform firstView when I go back using removeFromSuperView in secondView?
What do you want to do exactly ? maybe you just want to go from your first view controller to your second view controller ? and then go back to your first view controller ? in this case just do like this, if your first controller is already embbeded in a navigation controller:
[self.navigationController pushViewController:secondViewController animated:YES];
But if you just want to create a view from Interface Builder and then add it above your first view, you can use the notification center to post an event when you click on your Back button from your second view:
- (void) backButtonClicked:(id)sender {
[self.view removeFromSuperView];
[[NSNotificationCenter defaultCenter] postNotificationName:#"back"
object:self.view];
}
You can then add an observer for this event in your first view controller, like this:
- (void) pushSecondViewController {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(secondViewDidGoBack:)
name:#"back"
object:secondViewController.view];
SecondView *secondViewController = [[SecondView alloc] initWithNibName:#"SecondView"
bundle:nil];
[self.view addSubview:secondViewController.view];
}
- (void) secondViewDidGoBack:(NSNotification *)notification {
[[NSNotificationCenter defaultCenter] removeObserver:self];
NSLog(#"My Second View Did Go back !");
}
I hope this will help you !

UINavigationController navigationBarHidden

Hey everbody, i'm having problem with a simple question.
I have a NavigationController, 01.xib ans 02.xib.
I set in IB NavigationController to dont display the navigationBar. Well, when i go to 02.xib, i set it to appear.
[self navigationController].navigationBarHidden = NO;
Everything works fine.
But, when i come back to 01.xib with the top button, the bar still appearing in the 01.xib.
How can i fix that?
Thanks!
Use this in first view controller:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self navigationController] setNavigationBarHidden:YES animated:animated];
}
I believe this is happening because they are referencing the same navigation controller.
You could set it hidden again in the viewDidAppear method of your 01 class.
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[self navigationController].navigationBarHidden = YES;
}

Can't show a nagivationbar after hiding it

I have the following in the mainwindow.xib
Navigation Controller
List item
Tab bar controller
tabbar
firstViewController
SecondViewController
The entrypoint
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
navController.viewControllers = [NSArray arrayWithObject:tabBarController];
[window addSubview:navController.view];
[window makeKeyAndVisible];
return YES;
}
and now in the first viewcontroller i'm writing
-(void)loadView
{
if(rootAppDelegate==nil)
rootAppDelegate=(tabbarAppDelegate *) [[UIApplication sharedApplication]delegate];
listEmergencyItems= rootAppDelegate.listOfEmergencySectionItems;
self.rootAppDelegate.navController.navigationBarHidden = NO;
[super loadView];
}
and in the second viewcontroller i'm writing
- (void)loadView
{
if(rootAppDelegate==nil){
rootAppDelegate=(tabbarAppDelegate *) [[UIApplication sharedApplication]delegate];
}
listHospitalsItems= self.rootAppDelegate.listOfHospitalsItems;
self.rootAppDelegate.navController.navigationBarHidden = YES;
[super loadView];
}
And on the runtime, when it first loads the first view, i see the navigationbar where i need to navigate into a detail view.
And when i press the second tab bar item, i go to the second view, and the navigation bar gets hidden.
But when i press back on the first tabbar item, i.e. returning to the first viewcontroller. the navigation bar remains hidden.
Any idea?
The navigation bar won't show in the second view because neither view was placed on the navigationcontroller's stack. you want to use something like this in the parent to present a child view instead of overriding loadView
ViewToPresentViewController *myVController = [[ViewToPresentViewController alloc] initWithNibName:#"ViewToPresentViewController"
bundle:nil];
myVController.property = someValue;
[self.navigationController pushViewController:myVController
animated:YES];
[myVController release];
then, as i said previously, you can just use [self.navigationController setNavigationBarHidden:animated:]