Back Button in UINavigationBar Hide Problem

11,626

Solution 1

Set self.navigationItem.backBarButtonItem = nil;

Solution 2

viewController.navigationItem.hidesBackButton = YES;

This works perfectly!

Solution 3

Just used this and it works.

[self.navigationItem setHidesBackButton:YES animated:NO];
self.navigationItem.titleView.center = self.navigationController.navigationBar.center;

Solution 4

The property you are setting refers to how the "self" is represented when it is the "back" item in the navigation controller stack. I assume you are setting this in your "work calendar" view controller, it won't work unless that controller has further child views.

Try setting the navigation bar leftButtonItem property to nil instead.

Solution 5

The problem you are running into is because you are not changing your navigation bar's composition, you are just hiding part of it. When you set the hidden value of your button, you are doing just that, hiding it, not removing it. It will still take up space. To solve your problem you need to remove the button, then when you want the use to be able to navigate away, just add your button back.

Realistically though, if you are having display issues like this you should reconsider your navigation bar UI design and try to come up with a more effective button title.

Share:
11,626
jylee
Author by

jylee

Updated on June 11, 2022

Comments

  • jylee
    jylee almost 2 years

    When I use this: [self.navigationItem setHidesBackButton:YES animated:NO]; to hide the back button in my navigationBar, my title doesn't get centered. It prints like the button is still there.

    does anyone know why this happens, and how to fix it?

    EDIT:

    My program is like so: my rootViewController is a navigation controller, and I set that so the navigation bar is hidden. Then I push to another UIViewController, which I make the navigation bar appear again, but make the back button disappear.

    I tried the setting self.navigationItem.backBarButtonItem = nil;, but it didn't make the backbutton disappear.

    Here's some pictures for reference:

    Picture with back button Picture without

  • jylee
    jylee over 12 years
    I've tried that but it didn't seem to make the back button disappear. I've added more info to my question, please take a look at it if you can!
  • Legolas
    Legolas over 12 years
    is your problem with the title of the back button ?
  • Legolas
    Legolas over 12 years
    Okay. I can understand the problem now ! So yeah. do you want to remove the back button just because title is not centered, or do you want to remove the back button because you don't need it ?
  • Legolas
    Legolas over 12 years
    The reason why I asked that was because if you are doing that to make your title centered, you can just rename that to "back" self.navigationItem.backBarButtonItem.title = @"back";
  • jylee
    jylee over 12 years
    No, I want it completely gone because I don't need it.
  • iMeMyself
    iMeMyself over 11 years
    In my case self.navigationItem.hidesBackButton = YES; this worked :)