UINavigationController
iOS development
back button
Swift programming
interface customization

How to hide the back button in UINavigationController?

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

To hide the back button for a pushed view controller in UIKit, set the view controller's navigationItem.hidesBackButton property. That removes the default back button from the navigation bar, but you still need to think about how the user will leave the screen.

The Basic UIKit Solution

The simplest approach is to configure the current view controller's navigation item.

swift
1import UIKit
2
3final class DetailsViewController: UIViewController {
4    override func viewDidLoad() {
5        super.viewDidLoad()
6        navigationItem.hidesBackButton = true
7    }
8}

You can also use the animated setter:

swift
1override func viewWillAppear(_ animated: Bool) {
2    super.viewWillAppear(animated)
3    navigationItem.setHidesBackButton(true, animated: animated)
4}

This affects the current view controller after it has been pushed onto a UINavigationController stack.

When to Set It

viewDidLoad is fine when the back button should always be hidden for that screen. viewWillAppear is more flexible when the setting depends on state and may change over time.

The back button belongs to the navigation item shown for the current controller, so set the property on the destination controller, not on the previous one.

Provide Another Way Out

Apple's navigation guidance is straightforward: if you remove the usual back affordance, provide another way for the user to navigate. A common pattern is replacing the back button with a custom close or cancel button.

swift
1import UIKit
2
3final class EditProfileViewController: UIViewController {
4    override func viewDidLoad() {
5        super.viewDidLoad()
6
7        navigationItem.hidesBackButton = true
8        navigationItem.leftBarButtonItem = UIBarButtonItem(
9            barButtonSystemItem: .close,
10            target: self,
11            action: #selector(closeTapped)
12        )
13    }
14
15    @objc private func closeTapped() {
16        navigationController?.popViewController(animated: true)
17    }
18}

That keeps the flow explicit. The default back button is gone, but the user is not trapped.

Hiding the Whole Navigation Bar Is Different

Do not confuse hiding the back button with hiding the entire navigation bar. If you want to hide the whole bar, use the navigation controller API:

swift
1override func viewWillAppear(_ animated: Bool) {
2    super.viewWillAppear(animated)
3    navigationController?.setNavigationBarHidden(true, animated: animated)
4}
5
6override func viewWillDisappear(_ animated: Bool) {
7    super.viewWillDisappear(animated)
8    navigationController?.setNavigationBarHidden(false, animated: animated)
9}

That is a different decision with bigger UX implications.

Swipe-to-Go-Back Considerations

Hiding the back button does not always imply that all backward navigation is disabled. Depending on your navigation setup, the interactive pop gesture may still be available.

If your real goal is "the user must not go back from this screen," you need to think beyond the button:

  • should the swipe-back gesture be disabled
  • should the stack be reset instead of pushed
  • should the flow be modal instead of navigational

Simply hiding the back button changes appearance first, not necessarily navigation policy.

A State-Driven Example

Sometimes the button should be hidden only while a task is in progress.

swift
1final class UploadViewController: UIViewController {
2    var uploadInProgress = false
3
4    override func viewWillAppear(_ animated: Bool) {
5        super.viewWillAppear(animated)
6        navigationItem.setHidesBackButton(uploadInProgress, animated: animated)
7    }
8}

This keeps the navigation rule tied to application state instead of scattering UI changes across the codebase.

When the Previous Screen Controls the Title

Another common confusion is backBarButtonItem. That property customizes the title or appearance of the back button contributed by the previous view controller. It is not the main switch for hiding the button on the current screen. For hiding, hidesBackButton is the direct property you want.

Common Pitfalls

Setting hidesBackButton on the wrong view controller is a common mistake. The destination controller controls the back button displayed while it is visible.

Removing the back button without giving the user another exit path creates confusing navigation and can trap the user in the flow.

Hiding the button and assuming the interactive pop gesture is gone can lead to inconsistent behavior if the swipe gesture still works.

Using navigation-bar hiding APIs when you only meant to remove the back button changes much more of the interface than intended.

Summary

  • Hide the default back button with navigationItem.hidesBackButton = true or setHidesBackButton.
  • Set the property on the currently visible destination view controller.
  • If you remove the back button, provide another clear way to leave the screen.
  • Hiding the back button is different from hiding the entire navigation bar.
  • If you must block backward navigation completely, handle gestures and flow design, not just the button.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.