Skip to main content
Swift for iOS Development
CHAPTER 13 Beginner

Navigation and Tab Views in SwiftUI

Updated: May 16, 2026
6 min read

# CHAPTER 13

1. Introduction

A single-screen application is rarely enough to build a complete product. Users expect to tap an item in a list and slide over to a detailed view, or tap a button at the bottom of the screen to switch between their Home Feed, Search, and Profile. In iOS development, managing how screens interact with one another is called Routing. In this chapter, we will master Navigation and Tab Views in SwiftUI. We will explore the modern NavigationStack, build interactive NavigationLink buttons to push new screens onto the stack, and implement the industry-standard bottom TabView.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Implement a NavigationStack at the root of your application.
  • Transition between screens using NavigationLink.
  • Pass data from a Parent screen to a Child screen during navigation.
  • Add large and inline navigation titles to your screens.
  • Build a persistent bottom navigation bar using TabView.

3. The NavigationStack

Think of an iOS app like a deck of cards. You start with the Home screen. When you tap a button, you place a new "Detail" card *on top* of the Home screen. When you hit the "Back" button, you pop that card off the deck, returning to the Home screen. To enable this "stacking" behavior, your entire screen MUST be wrapped inside a NavigationStack.
swift
12345678910111213
import SwiftUI

struct HomeView: View {
    var body: some View {
        // Wrapping everything in a NavigationStack!
        NavigationStack {
            VStack {
                Text("Welcome Home")
            }
            .navigationTitle("Home") // This adds the big Apple header at the top!
        }
    }
}
Once you are inside a NavigationStack, you can create buttons that slide in new screens. This is done using a NavigationLink. It requires a destination (the View you want to slide to) and a label (what the button looks like).
swift
1234567891011121314151617181920212223242526272829
import SwiftUI

// The Destination Screen
struct DetailView: View {
    var body: some View {
        Text("You made it to the detail screen!")
            .navigationTitle("Details")
            // NavigationStack automatically gives us a "< Back" button!
    }
}

// The Home Screen
struct HomeView: View {
    var body: some View {
        NavigationStack {
            VStack {
                // The Button that triggers the transition!
                NavigationLink(destination: DetailView()) {
                    Text("Go to Details")
                        .foregroundColor(.white)
                        .padding()
                        .background(Color.blue)
                        .cornerRadius(10)
                }
            }
            .navigationTitle("Home")
        }
    }
}

5. Passing Data Between Screens

Often, you click on a specific product and want the next screen to show *that* product's details. You can easily pass data by injecting it into the child View's struct initialization!
swift
123456789101112131415161718192021222324252627
// 1. The Child Screen REQUIRES a String to be initialized
struct ProductDetailView: View {
    let productName: String 
    
    var body: some View {
        Text("Details for: \(productName)")
            .navigationTitle(productName)
    }
}

// 2. The Parent Screen passes the data in the NavigationLink!
struct StoreView: View {
    var body: some View {
        NavigationStack {
            VStack {
                NavigationLink(destination: ProductDetailView(productName: "iPhone 15")) {
                    Text("Buy iPhone")
                }
                
                NavigationLink(destination: ProductDetailView(productName: "MacBook Pro")) {
                    Text("Buy MacBook")
                }
            }
            .navigationTitle("Apple Store")
        }
    }
}

6. TabView (Bottom Navigation)

Instagram, Twitter, and WhatsApp all use a bottom navigation bar. In SwiftUI, this is incredibly easy to build using a TabView.
swift
1234567891011121314151617181920212223242526
import SwiftUI

struct MainAppView: View {
    var body: some View {
        TabView {
            // Tab 1
            HomeView()
                .tabItem {
                    Label("Home", systemImage: "house.fill")
                }
            
            // Tab 2
            Text("Search Screen")
                .tabItem {
                    Label("Search", systemImage: "magnifyingglass")
                }
            
            // Tab 3
            ProfileCardView() // Reusing the view from Chapter 12!
                .tabItem {
                    Label("Profile", systemImage: "person.fill")
                }
        }
        .accentColor(.purple) // Colors the currently active tab icon purple!
    }
}

7. Common Mistakes

  • Nesting NavigationStacks: A massive architectural mistake beginners make is putting a NavigationStack inside HomeView, and then putting *another* NavigationStack inside DetailView. This will cause the top navigation bars to double up, glitch out, and eventually crash the app. You only need ONE NavigationStack at the very root of your app. All child screens inherit it automatically!

8. Best Practices

  • Combining TabView and NavigationStack: If you use a TabView, where does the NavigationStack go? The rule is: The TabView is the root, and *each individual tab* gets its own NavigationStack!
``swift TabView { NavigationStack { HomeView() } // Correct! .tabItem { Label("Home", systemImage: "house") } } `

9. Exercises

  1. 1. Create a NavigationStack with a navigationTitle of "Settings".
  1. 2. Inside it, create a NavigationLink that transitions to a simple Text("Privacy Settings") view.

10. Coding Challenges

Challenge: Create a
TabView with two tabs: "Dashboard" and "Settings". Inside the "Dashboard" tab, build a NavigationStack containing a button that navigates to an "Analytics" screen. Ensure all tabs have appropriate SF Symbol icons.

11. MCQ Quiz with Answers

Question 1

Which SwiftUI component acts as the foundational wrapper required to enable sliding screen transitions and automatic "Back" buttons?

Question 2

When a user clicks a NavigationLink to transition from Screen A to Screen B, how does Screen B automatically receive a "Back" button at the top left?

12. Interview Questions

  • Q: Explain the mechanical difference between a NavigationStack and a NavigationLink. Which one manages the memory array of the screen hierarchy?
  • Q: Describe the catastrophic UI behavior that occurs when a developer accidentally nests a NavigationStack inside of another NavigationStack.
  • Q: When architecting an application that utilizes both bottom-bar tabs and sliding screen navigation, detail the hierarchical relationship between the TabView and the NavigationStacks.

13. FAQs

Q: How do I hide the back button and make a custom one? A: You can hide the default Apple back button by adding
.navigationBarBackButtonHidden(true) to the destination view. You can then create your own button that utilizes the @Environment(\.dismiss) variable to manually pop the screen off the stack!

14. Summary

In Chapter 13, we shattered the single-screen barrier and architected complex, multi-page routing systems. We deployed the modern
NavigationStack to manage our screen hierarchy history array. We engineered interactive NavigationLink triggers to seamlessly slide new destination views onto the stack, and learned how to dynamically inject data into those child screens during the transition. Finally, we constructed industry-standard persistent bottom navigation utilizing the powerful TabView` wrapper.

15. Next Chapter Recommendation

We can navigate between screens, but our UI is currently "dead". If a user clicks a "Like" button, the heart icon doesn't turn red. If they type in a text box, the screen doesn't update. We need memory. Proceed to the most important chapter in SwiftUI: Chapter 14: State Management in SwiftUI.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·