【发布时间】:2020-04-21 03:10:07
【问题描述】:
我正在尝试从 struct B 的 var b 的 var a 的 struct a 中设置 @State var 的值,但它不起作用。我需要使用@State var,因为我将它作为绑定传递。例如:
struct A : View {
@State var myBindableVar = ""
var body : some View {
TextField(self.$myBindableVar) ...
}
}
struct B : View {
@State var a : A
var body : some View {
Button(action: { self.a.myBindableVar = "???" }) { ... }
}
}
点击按钮时myBindableVar 未设置为"???"。为什么?
【问题讨论】:
-
Understanding @State and @Binding... 并按关键字搜索。