简体   繁体   中英

iOS - Hide navigation bar only on one view?

I have a login view controller that, upon successful login, pushes my user to another view controller (ViewControllerB). That being said, ViewControllerB is embedded in a UINavigationController that I've already formatted with a menu button.

Because I'm using a push segue from the login view controller, this segue causes my UINavigationBar to be covered with a blank nav bar and a back button (not cool). That said, I tried to hide the navigation controller from login view controller with the following code:

loginviewcontroller.m

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:animated];
}

When I do this, the unwanted navigation bar with the back button covering my other nav bar is removed! Great. However when I then navigate to other screens, my nav bar remains hidden (and I want it to appear once my user makes it past ViewControllerB).

I tried using a modal segue upon successful login, but of course, that keeps me from being able to navigate to other screens with segues upon login.

Any idea how I can go about doing this?

Add this:

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [self.navigationController setNavigationBarHidden:NO animated:animated];
}

You should embedin UINavigationController from your first Viewcontroller or your loginViewController and at this ViewController you will hide the navigation bar and for your next viewController you can unhide the navigationbar. It has worked for me.

swift 3

override func viewWillAppear(_ animated: Bool) {

                //for hide navigation bar in current view
    super.viewWillAppear(animated)

    self.navigationController?.setNavigationBarHidden(true, animated: animated)
}

override func viewWillDisappear(_ animated: Bool) {

                //for unhide in navigation bar in next/previous view
    super.viewWillDisappear(animated)

    self.navigationController?.setNavigationBarHidden(false, animated: animated)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM