NavigationLink的selected参数接受绑定,但我的ObservedObject有Bool变量,而不是可选值。如何将其转换为selected会接受它?
代码:
class RegistrationFlowEnvironment: ObservableObject {
@Published var done = false
}视图:
struct ContentView: View {
@ObservedObject var regFlowEnv = RegistrationFlowEnvironment()
var body: some View {
NavigationView {
VStack{
NavigationLink("Go to other place", destination: Dest(),
tag: true,
selection: $regFlowEnv.done)
}
}
}
}发布于 2020-09-15 19:26:39
这里是固定的变体(使用Xcode11.7/ iOS 13.7进行测试)
NavigationView {
VStack{
NavigationLink("Go to other place", destination: Text("Dest"),
tag: true,
selection: Binding($regFlowEnv.done))
}
}https://stackoverflow.com/questions/63900547
复制相似问题