From c3af224a350bbc4c34b5043273ef45a5a8127291 Mon Sep 17 00:00:00 2001 From: "art.dambrine" Date: Tue, 6 Apr 2021 09:52:38 +0200 Subject: [PATCH] programmatically navigate to view --- NavigationExemple/ContentView.swift | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/NavigationExemple/ContentView.swift b/NavigationExemple/ContentView.swift index 4d95fe4..045992c 100644 --- a/NavigationExemple/ContentView.swift +++ b/NavigationExemple/ContentView.swift @@ -7,31 +7,25 @@ import SwiftUI -struct ResultView: View { - var choice: String - - var body: some View { - Text("You chose \(choice)") - } -} struct ContentView: View { + @State private var isShowingDetailView = false + var body: some View { NavigationView{ VStack(alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/, spacing: 20){ - NavigationLink( - destination: ResultView(choice: "Heads")){ - Text("Chosing Heads") - .padding() + NavigationLink(destination: Text("Heads"), isActive: $isShowingDetailView){ + EmptyView() } - NavigationLink( - destination: ResultView(choice: "Tails")){ - Text("Chosing Tails") - .padding() + Button("Tap to show view"){ + // Some custom code here + // .. + self.isShowingDetailView = true } + }.navigationTitle("Menu principal") }