我无法找到一种方法,而不从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 Home")
NavigationLink(destination: ContentView()) {Text("Go")}
Text("Go back")
Button(action: { self.presentationMode.wrappedValue.dismiss() }) {Text("Go to ViewB")}
}.navigationBarTitle("ViewB")
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
在“旧的” Swift中,我可以轻松地进行unwindSegue之类的操作>
@IBAction func unwindToVCMain(segue:UIStoryboardSegue) { } }
并且像这样轻松地调用它>
performSegue(withIdentifier: "unwindToVcMain", sender: nil)
我无法找到一种方法,而不从ViewB转到ContentView,而无需在另一个NavigationView的顶部显示第二个NavigationView。 struct ContentView:视图{var body:some View {...
我也在寻找那种方法。我采用了两次调用self.presentationMode.wrappedValue.dismiss()
的方法,但与取消事务的行为并不完全相同。