SwiftUI - How to programatically load a new view from the current view (Xcode 15 beta 6)

35 Views Asked by At

The approaches that I used in earlier versions have stopped working, in fact they crash. The culprit is, I believe, TabView.

To load a new View as follows still works:

 NavigationLink(destination: NextView().navigationBarBackButtonHidden(true))   {
                        Text("Press to see the next view")
                    }

And if I want to load a TabView this will, initially, also still work (MenuView generates the TabView):

 NavigationLink(destination: MenuView().navigationBarBackButtonHidden(true))   {
                        Text("Press to Continue")
                           
 }

And the chosen View with the TabView at the bottom of the screen appears:

enter image description here

But from the next view how to I, programatically, go to another View? I used to be able to call:

HStack{
     Button(action: {selectedTab = TabChoice.calculate}, label: { Text("Press to go to next view")
     }
}

This no longer works and crashes to @main with no errors in the debug screen.

@main
struct MyApp: App {
var body: some Scene {
    WindowGroup {
        LaunchScreen()
        }
    }
}

Any ideas?

0

There are 0 best solutions below