How to hide 'Back' button on navigation bar on iPhone?

185,460

Solution 1

Objective-C:
self.navigationItem.hidesBackButton = YES;

Swift:
navigationItem.hidesBackButton = true

Solution 2

The best way is to combine these, so it will hide the back button even if you set it up manually :

self.navigationItem.leftBarButtonItem=nil;
self.navigationItem.hidesBackButton=YES;

Solution 3

hide back button with bellow code...

[self.navigationItem setHidesBackButton:YES animated:YES];

or

[self.navigationItem setHidesBackButton:YES];

Also if you have custom UINavigationBar then try bellow code

self.navigationItem.leftBarButtonItem = nil;

Solution 4

In Swift:

Add this to the controller

override func viewDidLoad() {
    super.viewDidLoad()
    self.navigationItem.setHidesBackButton(true, animated: false)
}

Solution 5

Use the code:

 self.navigationItem.backBarButtonItem=nil;
Share:
185,460
Chilly Zhong
Author by

Chilly Zhong

I'm a mobile app developer. I was developing for Windows Mobile and Blackberry. I begin to dig into iPhone Development since Feb, 2009. Working has become a brand-new page for me and for my life. I was working on a symbian app for a short time in March, 2010. And I begin to learn Android in Nov, 2010 and learn WindowsPhone in Nov, 2011. Now I'm working on an iOS framework similar to iAd and I'm happy to offer all kinds of libs to help other developers. Always walking down your own way and keep your faith.

Updated on July 08, 2022

Comments

  • Chilly Zhong
    Chilly Zhong almost 2 years

    I added a navigation control to switch between views in my app. But some of the views shouldn't have 'Back' (the previous title) button. Any ideas about how to hide the back button?