我找不到从 ViewB 转到 ContentView 而不NavigationView在另一个NavigationView.
struct ContentView: View {
var body: some View {
NavigationView{
VStack {
Text("Go to ViewA")
NavigationLink(destination: ViewA()) {Text("Go")}
}.navigationBarTitle("ContentView")
}
}
}
struct ViewA: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
VStack {
Text("Go to ViewB")
NavigationLink(destination: ViewB()) {Text("Go to B")}
Text("Go back")
Button(action: { self.presentationMode.wrappedValue.dismiss() }) {Text("Go to ContentView")}
}.navigationBarTitle("ViewA")
}
}
struct ViewB: View {
@Environment(\.presentationMode) var presentationMode
var body: some View {
VStack {
Text("Go …Run Code Online (Sandbox Code Playgroud)