Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS 8: UINavigationController hide back button

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.

like image 405
ZhukV Avatar asked Sep 23 '14 11:09

ZhukV


People also ask

How can remove back button in iOS?

You can do: [self. navigationItem setHidesBackButton:YES]; In your second view controller (the one you want to hide the button in).

How do I make my back button invisible?

Way 1: Touch “Settings” -> “Display” -> “Navigation bar” -> “Buttons” -> “Button layout”. Choose the pattern in “Hide navigation bar” -> When the app opens, the navigation bar will be automatically hidden and you can swipe up from the bottom corner of the screen to show it.

How do I hide the back button in Swiftui?

The . navigationBarBackButtonHidden(true) will hide the back button.


2 Answers

This worked for me.

-(void)viewWillAppear:(BOOL)animated {

    [super viewWillAppear:animated];

    [self.navigationItem setHidesBackButton:YES];
    [self.navigationItem setTitle:@"Home"];
}
like image 104
scrainie Avatar answered Oct 12 '22 08:10

scrainie


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
}
like image 40
eric f. Avatar answered Oct 12 '22 07:10

eric f.