您需要设置后退按钮将弹出到的视图的标题:
struct ContentView: View {
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailView()) {
Text("push view")
}
}.navigationBarTitle("", displayMode: .inline)
}
}
}
struct DetailView: View {
var body: some View {
Text("Detail View")
}
}
或者,根据呈现状态,有条件地设置或取消设置源视图的标题,您可以使用下面的代码。
请注意 isActive 参数有一个错误,但很可能很快就会解决。这是对提到的SwiftUI 错误的参考:NavigationDestinationLink deprecated
struct ContentView: View {
@State private var active: Bool = false
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: DetailView(), isActive: $active) {
Text("push view")
}
}.navigationBarTitle(!active ? "View Title" : "", displayMode: .inline)
}
}
}
struct DetailView: View {
var body: some View {
Text("Detail View")
}
}