سؤال

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top