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.
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.
You can also use the animated setter:
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.
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:
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.
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 = trueorsetHidesBackButton. - 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
- How to hide the keyboard when I press return key in a UITextField?
- How to hide the title bar for an Activity in XML with existing custom theme
- How to hide the title bar for an Activity in XML with existing custom theme
- How to hide UINavigationBar 1px bottom line
- How to hide UINavigationBar 1px bottom line
- How to hide underbar in EditText
- How to identify previous view controller in navigation stack
- How to ignore touch events and pass them to another subview's UIControl objects?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.