iPhone Show modal UITableViewController with Navigation bar
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
Introduction
If you present a UITableViewController directly, UIKit shows the table but not a navigation bar. The standard solution is to embed the table controller inside a UINavigationController and present that navigation controller modally.
Wrap the Table in a Navigation Controller
UITableViewController manages rows, sections, selection, and refresh behavior. It does not own navigation chrome. In UIKit, the navigation bar belongs to UINavigationController, which is why the bar appears only after you wrap the table screen in one.
This separation is useful because the same table controller can work in two modes. You can push it onto an existing navigation stack or present it modally in its own temporary stack.
Presenting the Modal Screen
The following Swift example creates a host controller, builds the table controller, wraps it in a navigation controller, and presents it:
The modal table controller configures its own title and dismissal button:
The key detail is that you present navigationController, not tableController.
Picking the Right Presentation Style
On recent iPhone versions, modal screens often appear as sheets instead of taking over the full display. That behavior is controlled by modalPresentationStyle.
Use .pageSheet or .formSheet for short flows such as choosing an option list or editing a small settings group. Use .fullScreen when the modal screen acts like a separate task and should feel more immersive.
If the user needs a confirmation action, add a done button with navigationItem.rightBarButtonItem. Because the bar belongs to the modal navigation stack, the button appears automatically once the modal is shown.
Storyboard-Based Apps
The same pattern applies when the table controller comes from a storyboard. Instantiate the controller, wrap it, and present the wrapper:
This keeps the presentation code consistent whether you build the UI in code or Interface Builder.
Common Pitfalls
The first mistake is presenting the table controller by itself. That shows the rows, but no navigation bar appears because nothing is managing navigation.
Another issue is forgetting a dismissal control. A modal screen that has a title bar but no cancel or done action quickly becomes awkward.
Developers also get confused by default sheet behavior on modern iOS versions. If the modal does not cover the whole screen, it may simply be using the system default presentation style.
Finally, keep row rendering lightweight. Rebuilding expensive views in cellForRowAt can make a small modal list feel sluggish.
Summary
- A
UITableViewControllerdoes not create a navigation bar on its own. - Wrap the table controller in
UINavigationControllerbefore presenting it modally. - Add cancel or done actions through
navigationItem. - Set
modalPresentationStyleexplicitly when the visual behavior matters. - The same wrapping pattern works for programmatic and storyboard-created controllers.
Related reading
- iPhone Simulator location
- iPhone UIButton - image position
- iPhone UITableView. How do turn on the single letter alphabetical list like the Music App?
- iPhone UITextField - Change placeholder text color
- iPhone UIView Animation Best Practice
- iPhone viewWillAppear not firing
- iPhone What is a WWDR intermediate certificate?
- iphone Where the .dSYM file is located in crash report
.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.