Combinando abas com pilhas
Dê a cada aba sua própria NavigationStack.
Combinando abas com pilhas é uma aula grátis de SwiftUI Academy no CoddyKit. Esta é a aula 4 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de SwiftUI Academy, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de SwiftUI Academy inclui 4 aulas no total.
Partes desta aula ainda não foram traduzidas e aparecem em inglês.
Tabs Plus Navigation
Most real apps let users tap a tab and then drill into detail screens. That means mixing TabView with NavigationStack. 🧭
One Stack per Tab
The pattern is simple: give every tab its own NavigationStack so each section has independent push and pop history.
Wrapping a Tab Screen
Put a NavigationStack inside each tab and place that tab content within it. The tab bar stays put while you navigate.
NavigationStack {
HomeScreen()
}
.tabItem { Label("Home", systemImage: "house") }Stack Lives Inside TabView
Order matters: NavigationStack goes inside the TabView, never the other way around, so the bar never scrolls away.
Independent History
Because each tab owns its stack, drilling deep in one tab leaves the others untouched when you come back.
A Full Combined Example
Here two tabs each wrap their screen in a stack, giving Home and Search their own navigation.
TabView {
NavigationStack { HomeScreen() }
.tabItem { Label("Home", systemImage: "house") }
NavigationStack { SearchScreen() }
.tabItem { Label("Search", systemImage: "magnifyingglass") }
}Pushing Detail Views
Inside a tab use NavigationLink as usual to push detail screens onto that tab own stack.
NavigationLink("Details") {
DetailScreen()
}Titles Stay Per Tab
Set navigationTitle inside each stack so every tab shows its own title in the bar at the top.
Switching Tabs Keeps Depth
Move to another tab and back and your position in that tab navigation is preserved, just like native apps.
Avoid Stacking the Bar
Never wrap the whole TabView in a single NavigationStack. That can push the tab bar around in odd ways.
A Scalable Structure
This tab-plus-stack layout scales cleanly. Add a tab, give it a stack, and the rest of the app keeps working. ✨
Quick Check
Let us check the right way to nest navigation with tabs.
Recap: Combining Tabs with Stacks
Wrap each tab content in its own NavigationStack inside the TabView, and every section gets independent navigation with a steady tab bar. 🎉
Aprenda Swift com um tutor de IA — grátis
Escreva e execute código real no seu navegador, obtenha ajuda instantânea de um tutor de IA 24/7 e continue de onde parou na web ou no app.
- Cursos
- 30
- Aulas
- 120
Perguntas Frequentes
A aula “Combinando abas com pilhas” é grátis?
Sim — o texto completo de “Combinando abas com pilhas” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de SwiftUI Academy, atualize para CoddyKit PRO. O curso de SwiftUI Academy inclui 4 aulas no total.
O que vou aprender em “Combinando abas com pilhas”?
Dê a cada aba sua própria NavigationStack. Você pratica SwiftUI Academy com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.
Preciso ter experiência prévia para começar SwiftUI Academy?
Nenhuma experiência prévia é necessária. SwiftUI Academy no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 4 de 4.
Quanto tempo leva a aula “Combinando abas com pilhas”?
A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.
Posso escrever e executar código nesta aula de SwiftUI Academy?
Sim. Cada aula de SwiftUI Academy inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.
Todas as aulas deste curso
- Criando uma barra de abas
- Itens de aba e distintivos
- Vinculação da aba selecionada
- Combinando abas com pilhas