18

After I run my application in iOS 8 (XCode 6.0.1, iPhone 6), the back button does not hide.

My code:

- (void)removeCategoriesButton
{
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
        [_navigationController.topViewController.navigationItem setHidesBackButton:YES];
        [_navigationController.topViewController.navigationItem setLeftBarButtonItem:nil];
    } else {
        UIViewController *controller = _app.window.rootViewController;

        if ([controller isKindOfClass:[UINavigationController class]]) {
            UINavigationController *nav = (UINavigationController *)controller;
            [nav.topViewController.navigationItem setHidesBackButton:YES];
            [nav.topViewController.navigationItem setLeftBarButtonItem:nil];
        }
    }
}

But the back button does not hide (see screenshot):

Simulator screen

UPD:

I run application in another simulators, and i see this "bug" only on iOS 8.

Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
ZhukV
  • 2,892
  • 6
  • 25
  • 36

11 Answers11

45

This worked for me.

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    [self.navigationItem setHidesBackButton:YES];
    [self.navigationItem setTitle:@"Home"];
}
Martin Herman
  • 888
  • 13
  • 34
scrainie
  • 461
  • 3
  • 2
15

I tried many of the answers but the only one that worked for me was:

    override func viewDidLoad() {
    super.viewDidLoad()

    let backButton = UIBarButtonItem(title: "", style: UIBarButtonItemStyle.Plain, target: navigationController, action: nil)
    navigationItem.leftBarButtonItem = backButton
}
eric f.
  • 906
  • 2
  • 9
  • 17
  • This works. Previously I'd tried `[self.navigationItem setHidesBackButton:YES];` but the back button text still remained. – nidheeshdas Aug 07 '15 at 11:15
6

Call on your ViewDidLoad the following method:

Objective-C:

self.navigationItem.leftBarButtonItem = nil;

or

self.navigationItem.hidesBackButton = YES;

Swift:

navigationItem.hidesBackButton = true
Chandresh Kachariya
  • 667
  • 2
  • 13
  • 31
LS_
  • 6,763
  • 9
  • 52
  • 88
  • I try call this code from `viewDidLoad` but not working. – ZhukV Sep 23 '14 at 13:03
  • Then try to call it on the ViewController that takes to this. For example if this is your second ViewController write the code I posted on the first ViewController ViewDidLoad method – LS_ Sep 23 '14 at 13:14
4

Swift:

self.navigationItem.hidesBackButton = true
William Hu
  • 15,423
  • 11
  • 100
  • 121
3

I found that this was caused by pushing a new view in viewWillAppear, if I moved it to viewDidAppear then the back button didn't show. Strange that this issue only appeared in iOS8.

2

Try this:

[self.navigationItem setHidesBackButton:YES];

for (UIView *view in self.navigationController.navigationBar.subviews)
{
    NSString *name = [NSString stringWithFormat:@"%@",view.class];
    if ([name isEqualToString:@"UINavigationItemButtonView"] || [name isEqualToString:@"_UINavigationBarBackIndicatorView"]) {
        [view setHidden:YES];
    }
}
1

Where have you written that code?

It should be as simple as in your view controller's loadView/viewDidLoad: method adding this

[self.navigationItem setHidesBackButton:YES];

This works for me on an iPhone 6

SomeGuy
  • 9,670
  • 3
  • 32
  • 35
1

Try to use self.navigationItem.hidesBackButton = true in viewWillAppear() method, this worked for me.

Oleg Novosad
  • 2,261
  • 1
  • 27
  • 28
1

Hiding the back button using setHidesBackButton only works if you have not customized the button.

From the method reference: "Specify true if the back button should be hidden when this navigation item is the top item. Specify false if the back button should be visible, assuming it has not been replaced by a custom item." (Note the last line)

The simply solution in that case is to first set the leftBarButtonItem to nil.

Swift 3.0:

self.navigationItem.leftBarButtonItem = nil
self.navigationItem.setHidesBackButton(true, animated: false)
Nico teWinkel
  • 870
  • 11
  • 19
0

This bug only happens when you use Storyboard. Another solution is add an UIBarButtonItem with empty title to "fake" it.

0

The only way I've found to do this is to hide the navigation bar and adding a navigation bar in storyboard and redisplay the navigation bar in the next ViewController. All I had to do is add a label in the status bar so that the navigation bar is uniform. I have found no other way...

screen

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

so that the navigation bar is displayed in the next viewcontroller, declare in:

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

}
oscar castellon
  • 3,048
  • 30
  • 19