【发布时间】:2022-01-15 09:21:53
【问题描述】:
从视图 A 导航到视图 B,我正在传递一个 var show 。视图 A 不再可见。
我需要一个 @State var stateShow ,其初始值与从 A 传递给 B 的值 show 相同。
不使用 onAppear 怎么办?谢谢
struct B : View {
public var show:Bool
@State private stateShow : Bool
init (_ show : Bool){
self.show = show
}
}
【问题讨论】:
-
可能,但据我所知
-
_stateShow = State(initialValue: show)