在gif中显示,一旦导航并关闭新视图,便无法导航回去!这是SwiftUI错误还是滥用NavigationLink?
struct ContentView: View {
var body: some View {
return NavigationView {
NavigationLink(destination: FakeView1()) {
Text("Navigate")
}
}
}
}
struct FakeView1: View {
var body: some View {
Text("Hey")
}
}
答案 0 :(得分:1)
这似乎是swiftUI错误。我也遇到了同样的问题,因此,我已经使用了这种解决方法。
struct ContentView: View {
@State var isFakeActive: Bool = false
var body: some View {
NavigationView {
NavigationLink(destination: FakeView1(isFakeActive: self.$isFakeActive), isActive: self.$isFakeActive) {
Text("Navigate")
}
}
}
}
对于您的FakeView1类。
struct FakeView1: View {
@Binding var isFakeActive: Bool
var body: some View {
Text("Hey")
.navigationBarItems(leading: Button(action: {
self.isFakeActive = false
}, label: {
HStack {
Image(systemName: "arrow.left")
Text("Back")
}
}))
}
}
我已经测试过,并且工作正常。
答案 1 :(得分:1)
它是模拟器错误。请尝试使用您的设备