SwiftUI-正确使用导航视图和图纸
导航视图和工作表有问题。我有以下流程: -ContentView:具有打开ContentView2工作表的按钮 -ContentView2:具有指向ContentView3的标题的NavigationLink -ContentView3:具有NavigationLink,无标题,可将用户定向到ContentView2 但是,当我设置上述流时,当用户在ContentView2和ContentView3之间来回移动时,我最终会得到堆叠的标题。当用户在两个视图之间来回移动时,如何防止出现这种情况,并且只有一个标题?谢谢SwiftUI-正确使用导航视图和图纸,swiftui,navigationbar,navigationlink,Swiftui,Navigationbar,Navigationlink,导航视图和工作表有问题。我有以下流程: -ContentView:具有打开ContentView2工作表的按钮 -ContentView2:具有指向ContentView3的标题的NavigationLink -ContentView3:具有NavigationLink,无标题,可将用户定向到ContentView2 但是,当我设置上述流时,当用户在ContentView2和ContentView3之间来回移动时,我最终会得到堆叠的标题。当用户在两个视图之间来回移动时,如何防止出现这种情况,并且
struct ContentView: View {
@State var showSheet = false
var body: some View {
Button("Click"){
self.showSheet.toggle()
}
.sheet(isPresented: $showSheet) {
ContentView2()
}
}
}
struct ContentView2: View {
var body: some View {
NavigationView {
NavigationLink(destination: ContentView3()){
Text("Click Here")
}
.navigationBarTitle("Bar Title", displayMode: .inline)
}
}
}
struct ContentView3: View {
var body: some View {
NavigationLink(destination: ContentView2()){
Text("Click Here")
}
}
}
在根目录中只需要一个
导航视图
,下面是更正的组件
struct ContentView: View {
@State var showSheet = false
var body: some View {
Button("Click"){
self.showSheet.toggle()
}
.sheet(isPresented: $showSheet) {
NavigationView { // only here !!
ContentView2()
}
}
}
}
struct ContentView2: View {
var body: some View {
NavigationLink(destination: ContentView3()){
Text("Click Here")
}
.navigationBarTitle("Bar Title", displayMode: .inline)
}
}