0

The screen transitions with NavigationLink. I want to return to the first screen by clicking the button on the third screen. How do you do it?

The following code returns from the third screen to the second screen.

struct FirstView: View {

    var body: some View {
        VStack {
            NavigationView {
                NavigationLink(
                    destination: SecondView()
                ) {
                    Text("next")
                }
            }
        }
    }
}


struct ThirdView: View {
    @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>

    var body: some View {
        VStack {
            Button(action: {
                self.presentationMode.wrappedValue.dismiss()
            }) {
                Text("next")
            }
        }
        .navigationBarTitle("Third", displayMode: .inline)
    }
}
Ika
  • 1,271
  • 1
  • 12
  • 20

1 Answers1

0

I had encountered this problem, too.

But I solved it already.

Here is the solution. Maybe it can work. Check this answer

Spencer Reid
  • 409
  • 3
  • 14