我在具有拆分视图(横向)的 iPad 上遇到了 NavigationLink 的一些问题。这是一个例子:
这是重现该问题的代码:
import SwiftUI
final class MyEnvironmentObject: ObservableObject {
@Published var isOn: Bool = false
}
struct ContentView: View {
@EnvironmentObject var object: MyEnvironmentObject
var body: some View {
NavigationView {
NavigationLink("Go to FirstDestinationView", destination: FirstDestinationView(isOn: $object.isOn))
}
}
}
struct FirstDestinationView: View {
@Binding var isOn: Bool
var body: some View {
NavigationLink("Go to SecondDestinationView", destination: SecondDestinationView(isOn: $isOn))
}
}
struct SecondDestinationView: View {
@Binding var isOn: Bool
var body: some View {
Toggle(isOn: $isOn) {
Text("Toggle")
}
}
}
// Somewhere in SceneDelegate
ContentView().environmentObject(MyEnvironmentObject())
有谁知道解决这个问题的方法?一个简单的解决方法是禁用拆分视图,但这对我来说是不可能的。