NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

How do I navigate back N views

Forums > SwiftUI

I have a menu / data entry system that prsents teh following screens:

HomeView -> Page1 -> Page2 -> Page3

On Page 3 the use can commit or cancel both buttons shoule return to the Home screen....

The Home View decalres itself as s NavigationView and then uses the followin menchanism to link to the child pages:

struct NavigationBarLink<V: View, T: Hashable> : View {
    @EnvironmentObject var screenCoordinator: ScreenCoordinator

    var destination: V
    var tag: T
    var active: Bool
    @Binding var selection : T?

    var body: some View {
        ZStack {
            NavigationLink(destination: destination,
                           tag: tag,
                           selection: $selection) {
            }.hidden().frame(height: 0)
            Button("Next") {
                self.selection = self.tag

This allows me to jump back to the first linked view (i.e.Page1) but I cannot jump back to the HomeView. Is there a way to unwind the full NavigationStack?

I have also noticed that if the HomeView is a Form and the NavigationLink to Page1 is within the form the layout of the child Views is corrupted - I guess this is yet another SwiftUI bug.

Over the past month I have come to realise that SwiftUI needs a huge amount of development before it can be used in a large project.

Is there a site that has a list of the known SwiftUI bugs and worlarounds - it would be nice to know as I have wasted far too much time solving issues with the Framework


Hacking with Swift is sponsored by Essential Developer

SPONSORED From January 26th to 31st you can join a FREE crash course for iOS devs who want to achieve an expert level of technical and practical skills – it’s the fast track to being a senior developer!

Save your spot now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.