[英]How to access parent view variable without passing as binding in swiftUI
我正在使用showCommentView
变量,它是我在子视图中传递的@State
变量,因为@Binding
这里的问题是我需要作为绑定传递的每个子视图。 我怎样才能独立实现它
struct AudioListView: View {
@State var showCommentView = false
SecondView(showCommentView: $showCommentView)
}
struct SecondView {
@Binding var showCommentView:Bool
}
我认为您应该将showCommentView
变量作为绑定传递,如下所示:
struct AudioListView: View {
@State var showCommentView = false
SecondView(showCommentView: .constant(showCommentView))
}
struct SecondView {
@Binding var showCommentView:Bool
}
如果你想使用 is @State
或@Binding
你可以随意使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.